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

Adds ignore_unmapped option to nested and P/C queries #17748

Merged
merged 1 commit into from
Apr 14, 2016
Merged

Adds ignore_unmapped option to nested and P/C queries #17748

merged 1 commit into from
Apr 14, 2016

Conversation

colings86
Copy link
Contributor

The change adds a new option to the nested, has_parent, has_children and parent_id queries: ignore_unmapped. If this option is set to false, the toQuery method on the QueryBuilder will throw an exception if the type/path specified in the query is unmapped. If the option is set to true, the toQuery method on the QueryBuilder will return a MatchNoDocsQuery. The default value is falseso the queries work how they do today (throwing an exception on unmapped paths/types)

fail("expected has_children query on unmapped field to fail when ignore_unmapped is false");
} catch (QueryShardException e) {
assertThat(e.getMessage(), containsString("[" + HasChildQueryBuilder.NAME + "] no mapping found for type [unmapped]"));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use expectThrows instead? I think we should use it rather than this try:fail/catch:check_msg pattern for new code.

@jpountz
Copy link
Contributor

jpountz commented Apr 14, 2016

A minor concern I have is that ignore_unmapped: false is a double negation, which could get confusing. Otherwise the change looks good and well tested.

@martijnvg
Copy link
Member

maybe we should name this setting fail_unmapped? (and then default to true)

@colings86
Copy link
Contributor Author

I'm ok with changing it to fail_unmapped although we seem to use ignore_* elsewhere in the api including ignore_malformed which is a bit of a double negation too. What do you think @jpountz and @clintongormley ?

@clintongormley
Copy link
Contributor

ignore_unmapped defaults to false, so the only time the user will use this will be to set ignore_unmapped: true, which I think is OK.

@clintongormley
Copy link
Contributor

Docs LGTM

@@ -464,12 +502,12 @@ protected boolean doEquals(HasChildQueryBuilder that) {
&& Objects.equals(scoreMode, that.scoreMode)
&& Objects.equals(minChildren, that.minChildren)
&& Objects.equals(maxChildren, that.maxChildren)
&& Objects.equals(innerHitBuilder, that.innerHitBuilder);
&& Objects.equals(innerHitBuilder, that.innerHitBuilder) && Objects.equals(ignoreUnmapped, that.ignoreUnmapped);
Copy link
Contributor

Choose a reason for hiding this comment

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

let's put it on the next line to be consistent?

@jpountz
Copy link
Contributor

jpountz commented Apr 14, 2016

LGTM

The change adds a new option to the `nested`, `has_parent`, `has_children` and `parent_id` queries: `ignore_unmapped`. If this option is set to false, the `toQuery` method on the QueryBuilder will throw an exception if the type/path specified in the query is unmapped. If the option is set to true, the `toQuery` method on the QueryBuilder will return a MatchNoDocsQuery. The default value is `false`so the queries work how they do today (throwing an exception on unmapped paths/types)
@colings86 colings86 merged commit 686aff1 into elastic:master Apr 14, 2016
@colings86 colings86 deleted the enhance/ignoreUnmappedNestedPC branch April 14, 2016 09:38
This was referenced Apr 14, 2016
@clintongormley clintongormley changed the title Adds ignore_unmapped option to nested and P/C queries Adds ignore_unmapped option to nested and P/C queries May 2, 2016
russcam added a commit to elastic/elasticsearch-net that referenced this pull request Jun 14, 2016
russcam added a commit to elastic/elasticsearch-net that referenced this pull request Jun 16, 2016
@clintongormley clintongormley added :Search/Search Search-related issues that do not fall into other categories and removed :Query DSL labels Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search/Search Search-related issues that do not fall into other categories v5.0.0-alpha2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants