Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failure for validate API on a terms query #29483

Merged
merged 16 commits into from
May 1, 2018

Conversation

pcsanwald
Copy link
Contributor

Fixes #29033, currently WIP as I need to fix a few integration tests. As @colings86 described on the issue, we're missing a step for terms queries, we need to rewrite the query on the coordinating node.

Steps to reproduce (and confirm fix)

  1. Run a local server: ./gradlew server

  2. create index curl -XPUT 'localhost:9200/twitter' -H 'Content-Type: application/json' -d'{}'

  3. add mapping curl -XPUT 'localhost:9200/twitter/_mapping/_doc' -H 'Content-Type: application/json' -d'{ "properties": { "user": { "type": "integer" }, "followers": { "type": "integer" } } }'

  4. run a validate request on a terms query: curl -XPOST 'localhost:9200/twitter/_validate/query?explain=true' -H 'Content-Type: application/json' -d'{ "query": { "terms": { "user": { "index": "twitter", "type": "_doc", "id": "2", "path": "followers" } } } }'

@pcsanwald pcsanwald added the WIP label Apr 11, 2018
@pcsanwald pcsanwald changed the title Fix incorrect failure when validating terms query Fix incorrect failure when using validate API on a terms query Apr 11, 2018
@pcsanwald pcsanwald changed the title Fix incorrect failure when using validate API on a terms query Fix failure for validate API on a terms query Apr 11, 2018
Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments.

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail precommit.

import org.elasticsearch.search.internal.AliasFilter;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.search.internal.ShardSearchLocalRequest;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.RemoteClusterAware;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see a lot of unnecessary imports here.

ActionListener<org.elasticsearch.index.query.QueryBuilder> rewriteListener = ActionListener.wrap(rewrittenQuery -> {
request.query(rewrittenQuery);
super.doExecute(task, request, listener);
}, ex -> {
Copy link
Contributor Author

@pcsanwald pcsanwald Apr 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this section (with advice from @imotov) to address a deficiency in the code uncovered by one of our integration tests, org.elasticsearch.validate.SimpleValidateQueryIT.testExplainValidateQueryTwoNodes, which tests an error case. Because originally I was propagating the listener's onError method, an XContent exception was being thrown by the server (bad!), rather than wrapped in a response that wraps the error according to our conventions (good! yay, integration tests!).

My "fix" raises a few questions about what the right response looks like, given this context.

@pcsanwald
Copy link
Contributor Author

Added some integration test fixes, and my own comments about those fixes; I could use some advice on the best way to handle this error in the right way at the point in execution where it's occurring (on the coordinating node, so there are no shards involved yet in the query).

@colings86 colings86 added the :Search/Search Search-related issues that do not fall into other categories label Apr 12, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@colings86 colings86 added the >bug label Apr 12, 2018
@pcsanwald
Copy link
Contributor Author

@jpountz happy to wait

Copy link
Contributor

@colings86 colings86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pcsanwald I left some comments

@@ -111,7 +113,7 @@
}
}
rewriteResponse.onResponse(builder);
} catch (IOException ex) {
} catch (IOException|XContentParseException|ParsingException ex) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of XContentParseException I think we should catch its super class IllegalArgumentException here since I know that we often throw IllegalArgumentException when validating requests as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder about this comment in case you missed it before?

}
List<QueryExplanation> explanations = new ArrayList<>();
// TODO[PCS]: given that we can have multiple indices, what's the best way to include
// these in a query explanation?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this TODO still needs to be resolved? I don't have a good solution here other than having something like "__coordinating_node_rewrite__" in place of the index name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this TODO can be removed now?

false,
explanations,
// TODO[PCS]: is it correct to have 0 for total shards if the request is invalidated before
// it makes it to the shards? I think the answer is probably no?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this TODO still needs to be resolved? Again I don't have a great solution here but given that it never made it onto any shard it is true that there were 0 total shards involved in the request, of which 0 succeeded and 0 failed so maybe this is ok?

Copy link
Contributor

@colings86 colings86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pcsanwald I think this is close, I left a couple of comments but they should be quick fixes. I also left a comment on the version checks and how they will need to be dealt with through back-porting to 6.x. I'm happy to walk through this process in more detail with you if you would like.

}
List<QueryExplanation> explanations = new ArrayList<>();
// TODO[PCS]: given that we can have multiple indices, what's the best way to include
// these in a query explanation?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this TODO can be removed now?

out.writeOptionalString(index);
} else {
out.writeString(index);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should back port this fix to 6.4. These version checks are fine to leave here for now but when you back port you will need to change them to Version.V_6_4_0 in the back ported commit on the 6.x branch an then after that add a new commit to the master branch to change these checks to Version.V_6_4_0 on master too. This process avoids getting CI failures before you've had a chance to back port the commit to 6.x.

@@ -111,7 +113,7 @@
}
}
rewriteResponse.onResponse(builder);
} catch (IOException ex) {
} catch (IOException|XContentParseException|ParsingException ex) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder about this comment in case you missed it before?

@elastic elastic deleted a comment from jpountz Apr 27, 2018
@pcsanwald
Copy link
Contributor Author

@elasticmachine please test this

@pcsanwald
Copy link
Contributor Author

@elasticmachine test this please

Copy link
Contributor

@colings86 colings86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pcsanwald pcsanwald merged commit 00b21f8 into elastic:master May 1, 2018
pcsanwald pushed a commit to pcsanwald/elasticsearch that referenced this pull request May 1, 2018
* WIP commit to try calling rewrite on coordinating node during TransportSearchAction

* Use re-written query instead of using the original query

* fix incorrect/unused imports and wildcarding

* add error handling for cases where an exception is thrown

* correct exception handling such that integration tests pass successfully

* fix additional case covered by IndicesOptionsIntegrationIT.

* add integration test case that verifies queries are now valid

* add optional value for index

* address review comments: catch superclass of XContentParseException

fixes elastic#29483
dnhatn added a commit that referenced this pull request May 2, 2018
* master: (68 commits)
  [DOCS] Removes X-Pack Elasticsearch release notes (#30272)
  Correct an example in the top-level suggester documentation. (#30224)
  [DOCS] Removes broken link
  [DOCS] Adds file realm configuration details (#30221)
  [DOCS] Adds PKI realm configuration details (#30225)
  Fix a reference to match_phrase_prefix in the match query docs. (#30282)
  Fix failure for validate API on a terms query (#29483)
  [DOCS] Fix 6.4-specific link in changelog (#30314)
  Remove RepositoriesMetaData variadic constructor (#29569)
  Test: increase authentication logging for debugging
  [DOCS] Removes redundant SAML realm settings (#30196)
  REST Client: Add Request object flavored methods (#29623)
  [DOCS] Adds changelog to Elasticsearch Reference (#30271)
  [DOCS] Fixes section error
  SQL: Teach the CLI to ignore empty commands (#30265)
  [DOCS] Adds Active Directory realm configuration details (#30223)
  [DOCS] Removes redundant file realm settings (#30192)
  [DOCS] Fixes users command name (#30275)
  Build: Move gradle wrapper jar to a dot dir (#30146)
  Build: Log a warning if disabling reindex-from-old (#30304)
pcsanwald pushed a commit that referenced this pull request May 3, 2018
* Fix failure for validate API on a terms query (#29483)

* WIP commit to try calling rewrite on coordinating node during TransportSearchAction

* Use re-written query instead of using the original query

* fix incorrect/unused imports and wildcarding

* add error handling for cases where an exception is thrown

* correct exception handling such that integration tests pass successfully

* fix additional case covered by IndicesOptionsIntegrationIT.

* add integration test case that verifies queries are now valid

* add optional value for index

* address review comments: catch superclass of XContentParseException

fixes #29483

* Backport terms-query-validate-bug changes to 6.x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search/Search Search-related issues that do not fall into other categories v6.4.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate API fails when validating Terms query
4 participants