Skip to content

Conversation

@liketic
Copy link

@liketic liketic commented Sep 28, 2017

Resolves #26799 . I'm trying to raise a IllegalArgumentException if the validation is failed. But I think it maybe not the best resolution, happy to hear your comments.

@elasticmachine
Copy link
Collaborator

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

@bleskes
Copy link
Contributor

bleskes commented Sep 28, 2017

@javanna it seems you were involved in the discuss on the relevant ticket. Care to take a look?

@javanna javanna self-requested a review September 28, 2017 13:16
@javanna javanna self-assigned this Sep 28, 2017
Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

Thanks a lot for your PR! I would have gone for IllegalArgumentException too, good choice. Adding a new exception has the disadvantage of needing to be supported by our serialization layer, which is a bit overkill in this case. Would you be up for adding a bit more test coverage? Some of the messages that you changed are not tested at all, it would be nice for instance to have a unit test for DefaultSearchContext and test the preProcess method if possible?

Copy link
Member

Choose a reason for hiding this comment

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

I would also make the same change for "Cannot use [sort] option in conjunction with [rescore]." .

Copy link
Member

Choose a reason for hiding this comment

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

we are not testing here the response code. Better to replace with catch: bad_request. That way we don't check the message, but we make sure that 400 is returned.

@javanna javanna added :Search/Search Search-related issues that do not fall into other categories >enhancement labels Oct 5, 2017
@liketic
Copy link
Author

liketic commented Oct 5, 2017

OK. Will do. Thanks for reviewing this PR.

@liketic
Copy link
Author

liketic commented Oct 6, 2017

@javanna Please review again.

Copy link
Member

Choose a reason for hiding this comment

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

this one will start a node, which makes it more of an integration test, would it be possible to make it extend ESTestCase?

Copy link
Author

Choose a reason for hiding this comment

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

Updated. Please review again.

@liketic
Copy link
Author

liketic commented Oct 9, 2017

@javanna Could you please review again? Thanks in advance.

@javanna
Copy link
Member

javanna commented Oct 9, 2017

@elasticmachine test this please

@javanna
Copy link
Member

javanna commented Oct 9, 2017

retest this please

@liketic
Copy link
Author

liketic commented Oct 9, 2017

@javanna Seems like the testing is failed. Can I rebase this branch?

@javanna
Copy link
Member

javanna commented Oct 10, 2017

@liketic feel free to rebase

@liketic liketic force-pushed the bugfix/issues/26799 branch from 4ce89b4 to f421d9a Compare October 10, 2017 10:16
@liketic
Copy link
Author

liketic commented Oct 10, 2017

@javanna Rebased. Please run test again. Thanks.

@javanna
Copy link
Member

javanna commented Oct 10, 2017

retest this please

@liketic
Copy link
Author

liketic commented Oct 10, 2017

@javanna I think the test failure is unrelated. Any thoughts?

@javanna
Copy link
Member

javanna commented Oct 10, 2017

@liketic the last failure is related to your changes. What fails is a backwards compatibility test, which makes sense as your change is breaking backwards compatibility, although for a good cause.

Failure at [scroll/12_slices:106]: expected [400] status code but api [search] returned [500 Internal Server Error] [{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"The number of slices [1025] is too large. It must be less than [1024]. This limit can be set by changing the [index.max_slices_per_scroll] index level setting.","stack_trace":"[The number of slices [1025] is too large. It must be less than [1024]. This limit can be set by changing the [index.max_slices_per_scroll] index level setting.]; nested: IllegalArgumentException[The number of slices [1025] is too large. It must be less than [1024]. This limit can be set by changing the [index.max_slices_per_scroll] index level setting.];

When running scroll/12_slices/Sliced scroll with invalid arguments against previous versions of Elasticsearch, a different response code is returned compared to what the updated test expects now. You need to add a skip section based on version as follows:

  - skip:
      version: " - 6.0.0-rc1"
      reason: Prior versions return 500 rather than 404

@liketic
Copy link
Author

liketic commented Oct 11, 2017

@javanna Thanks a lot! I tried to add this section to yaml, but I found the yaml parser cannot parse version 6.0.0-rc1, I have to create another PR #26964 to fix that. May I ask you to review that too?

@javanna
Copy link
Member

javanna commented Oct 11, 2017

@liketic my bad, we should rather skip " - 6.99.99" as this change will go to master only (and will be released with 7.0). Would you also mind adding a note to the migrate guide (migrate_7_0.asciidoc) about it?

@javanna
Copy link
Member

javanna commented Oct 11, 2017

retest this please

@liketic
Copy link
Author

liketic commented Oct 14, 2017

@javanna Thanks for your patient. I updated the doc, any comments are appreciated.

@javanna
Copy link
Member

javanna commented Oct 23, 2017

retest this please

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

hi @liketic thanks for your changes, I left a couple more comments but this is very close!

--------------------------------------------------
// CONSOLE

=== Scroll search will response `bad request` if request is invalid
Copy link
Member

Choose a reason for hiding this comment

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

I think we can skip the java exception names here given that this guide is read by all our users, also the ones that are not familiar with Java. Let's focus on response codes only. Also I would make the title shorter:

=== `_search/scroll` returns `400` for invalid requests

The `/_search/scroll` endpoint returns `400 - Bad request` when the request invalid, while it would previously return `500 - Internal Server Error` in such case.

if (filters.size() > maxFilters){
throw new QueryPhaseExecutionException(context,
throw new IllegalArgumentException(
"Number of filters is too large, must be less than or equal to: [" + maxFilters + "] but was ["
Copy link
Member

Choose a reason for hiding this comment

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

could we have a unit test for this change too?

Copy link
Author

Choose a reason for hiding this comment

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

Yes.


public class DefaultSearchContextTests extends ESTestCase {

public void testPreProcess() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

thanks a lot for taking the time to write this!

private void contextScrollKeepAlive(SearchContext context, long keepAlive) throws IOException {
if (keepAlive > maxKeepAlive) {
throw new QueryPhaseExecutionException(context,
throw new IllegalArgumentException(
Copy link
Member

Choose a reason for hiding this comment

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

do you think it would be possible to have a unit test for this too?

Copy link
Author

Choose a reason for hiding this comment

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

It's not easy to add unit test for this. The SearchServiceTests is also extend ESSingleNodeTestCase for other test cases. And this has been covered by the integration test. I can try to add a unit test if you think it's necessary.

}
AdjacencyMatrixAggregationBuilder builder = new AdjacencyMatrixAggregationBuilder("dummy", filters);
try {
builder.doBuild(context, null, new AggregatorFactories.Builder());
Copy link
Member

Choose a reason for hiding this comment

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

can you use expectThrows here instead?

Copy link
Author

Choose a reason for hiding this comment

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

my bad. Thanks.

AggregatorFactory<?> factory = builder.doBuild(context, null, new AggregatorFactories.Builder());
assertThat(factory instanceof AdjacencyMatrixAggregatorFactory, is(true));
assertThat(factory.name(), equalTo("dummy"));
}
Copy link
Member

Choose a reason for hiding this comment

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

thanks a lot for adding this test!

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

I did a last review round, this looks good, I left one minor remark but nothing blocking, I will merge once you made that minor change.

@liketic
Copy link
Author

liketic commented Oct 27, 2017

Hi @javanna , can we merge this now? Thanks! 😃

@javanna javanna added the >bug label Oct 30, 2017
@javanna javanna merged commit c3e2bdf into elastic:master Oct 31, 2017
@javanna
Copy link
Member

javanna commented Oct 31, 2017

thanks @liketic merged to the master branch.

@liketic liketic deleted the bugfix/issues/26799 branch October 31, 2017 11:18
javanna added a commit that referenced this pull request Oct 31, 2017
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Nov 1, 2017
* master:
  Enhances exists queries to reduce need for `_field_names` (elastic#26930)
  Added new terms_set query
  Set request body to required to reflect the code base (elastic#27188)
  Update Docker docs for 6.0.0-rc2 (elastic#27166)
  Add version 6.0.0
  Docs: restore now fails if it encounters incompatible settings (elastic#26933)
  Convert index blocks to cluster block exceptions (elastic#27050)
  [DOCS] Link remote info API in Cross Cluster Search docs page
  Fix Laplace scorer to multiply by alpha (and not add) (elastic#27125)
  [DOCS] Clarify migrate guide and search request validation
  Raise IllegalArgumentException if query validation failed (elastic#26811)
  prevent duplicate fields when mixing parent and root nested includes (elastic#27072)
  TopHitsAggregator must propagate calls to `setScorer`. (elastic#27138)
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Nov 2, 2017
* master:
  Remove checkpoint tracker bit sets setting
  Fix stable BWC branch detection logic
  Fix logic detecting unreleased versions
  Enhances exists queries to reduce need for `_field_names` (elastic#26930)
  Added new terms_set query
  Set request body to required to reflect the code base (elastic#27188)
  Update Docker docs for 6.0.0-rc2 (elastic#27166)
  Add version 6.0.0
  Docs: restore now fails if it encounters incompatible settings (elastic#26933)
  Convert index blocks to cluster block exceptions (elastic#27050)
  [DOCS] Link remote info API in Cross Cluster Search docs page
  Fix Laplace scorer to multiply by alpha (and not add) (elastic#27125)
  [DOCS] Clarify migrate guide and search request validation
  Raise IllegalArgumentException if query validation failed (elastic#26811)
  prevent duplicate fields when mixing parent and root nested includes (elastic#27072)
  TopHitsAggregator must propagate calls to `setScorer`. (elastic#27138)
jasontedor added a commit that referenced this pull request Nov 2, 2017
* master:
  Lazy initialize checkpoint tracker bit sets
  Remove checkpoint tracker bit sets setting
  Fix stable BWC branch detection logic
  Fix logic detecting unreleased versions
  Enhances exists queries to reduce need for `_field_names` (#26930)
  Added new terms_set query
  Set request body to required to reflect the code base (#27188)
  Update Docker docs for 6.0.0-rc2 (#27166)
  Add version 6.0.0
  Docs: restore now fails if it encounters incompatible settings (#26933)
  Convert index blocks to cluster block exceptions (#27050)
  [DOCS] Link remote info API in Cross Cluster Search docs page
  Fix Laplace scorer to multiply by alpha (and not add) (#27125)
  [DOCS] Clarify migrate guide and search request validation
  Raise IllegalArgumentException if query validation failed (#26811)
  prevent duplicate fields when mixing parent and root nested includes (#27072)
  TopHitsAggregator must propagate calls to `setScorer`. (#27138)
@rjernst
Copy link
Member

rjernst commented Mar 20, 2018

I'm going to backport this to 6.x. I do not view this as breaking, the previous behavior was not intended, and it would only affect a user who is catching this error and trying to decide what to do based on it, and action based on that catching would likely be incorrect.

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 v7.0.0-beta1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants