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

Queries and unmapped fields #12016

Closed
clintongormley opened this issue Jul 3, 2015 · 8 comments
Closed

Queries and unmapped fields #12016

clintongormley opened this issue Jul 3, 2015 · 8 comments
Labels
>enhancement :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch

Comments

@clintongormley
Copy link
Contributor

As discussed in #11806, different queries handle unmapped fields differently. The nested, has_child, has_parent, geo_*, and function_score query throw exceptions, while all of the others match no docs instead.

We need to make the behaviour uniform across queries.

The solution we came up with in FixItFriday is:

  • if a field doesn't exist in an index, then replace the query with a FieldNotFound query, which matches no documents
  • if explain is turned on, then the field_not_found query will be part of the output
  • if the strict_mappings is passed, then the request will throw a field not found exception instead.

This preserves the ease of use of, eg:

GET _search?name=john

without making search requests even more verbose, but makes debugging bad field names easy.

@martijnvg
Copy link
Member

Maybe we should then also have a FieldNotFound agg to have similar behaviour for aggs too?

@nik9000
Copy link
Member

nik9000 commented Jul 3, 2015

Maybe we should then also have a FieldNotFound agg to have similar behaviour for aggs too?

From a migration standpoint its always better to return no results than to blow up. I often deploy code that relies on the "if the field isn't there then nothing happens" behavior and create the field over time. Its just more sane that way. So I'm +1 on that.

Last I checked the term and phrase suggester return exceptions if the field doesn't exist and it'd be nicer if they didn't. Not critical. Just nicer.

@rjernst
Copy link
Member

rjernst commented Jul 4, 2015

Having a "field not found" query seems very odd (just the name). What about returning a MatchNoDocsQuery, but extending that to have a message about why match no docs was chosen (essentially giving a reason, since match no docs alone doesn't make any sense when building a real query)?

@clintongormley
Copy link
Contributor Author

@rjernst makes sense

MaineC pushed a commit to MaineC/elasticsearch that referenced this issue Sep 10, 2015
This add equals, hashcode, read/write methods, validation, separates toQuery
and JSON parsing and adds serialization and query generation tests.

Deprecates two types of initializing the bounding box: In our documentation we
speak about specifying top/left and bottom/right corner of a bounding box. Here
we also allow for top/right and bottom/left. This adds not only to the amount
of code but also testing needed w/o too much benefit for the user other than
more chances to confuse top/right/bottom/left/latitude/longitude IMHO.

Missing: The toQuery method with type set to "indexed" is not tested at the
moment.

Cleanup changes unrelated to base refactoring:
* Switched from type String to enum for types in GeoBoundingBoxQueryBuilder.
* Switched to using type GeoPoint for storing the bounding box coordinates
  instead of array of double values.

Relates to elastic#10217 for the query refactoring part.
Relates to elastic#12016 for how missing mappings are handled.

Adds a utility class for generating random geo data.

Adds some missing documentation.

Extend test to MEMORY type config
MaineC pushed a commit to MaineC/elasticsearch that referenced this issue Sep 20, 2015
This add equals, hashcode, read/write methods, validation, separates toQuery
and JSON parsing and adds serialization and query generation tests.

Deprecates two types of initializing the bounding box: In our documentation we
speak about specifying top/left and bottom/right corner of a bounding box. Here
we also allow for top/right and bottom/left. This adds not only to the amount
of code but also testing needed w/o too much benefit for the user other than
more chances to confuse top/right/bottom/left/latitude/longitude IMHO.

Missing: The toQuery method with type set to "indexed" is not tested at the
moment.

Cleanup changes unrelated to base refactoring:
* Switched from type String to enum for types in GeoBoundingBoxQueryBuilder.
* Switched to using type GeoPoint for storing the bounding box coordinates
  instead of array of double values.

Relates to elastic#10217 for the query refactoring part.
Relates to elastic#12016 for how missing mappings are handled.

Adds a utility class for generating random geo data.

Adds some missing documentation.

Extend test to MEMORY type config

Fix final review comments and rebase
@spinscale spinscale added v2.3.0 and removed v2.2.0 labels Dec 23, 2015
@colings86
Copy link
Contributor

We now have #17748 and #17751 which add an ignore_unmapped option to nested, parent/child and geo queries so the user can optionally ignore unmapped field or have an error reported. There is also a missing option that can be used on fieldValueFactor in the FunctionScoreQuery. Will those we can deal with unmapped fields on all queries so I'm going to close this issue. If people disagree we can reopen and discuss

@jpountz jpountz removed the v2.4.0 label Apr 14, 2016
@colings86 colings86 removed the help wanted adoptme label Apr 14, 2016
@tragiclifestories
Copy link

Will those we can deal with unmapped fields on all queries so I'm going to close this issue.

How do any of these help with a bool query? Use case is a variant on the 'multiple indices' one: I've recently started indexing a field that is used to exclude results with bool/must_not. This works with 2.4, not with 5.x. I don't see how this could be rewritten as any of the queries that support ignore_unmapped

@audriusbugas
Copy link

It still does not work with simple terms filter and others. That's a bit sad. Since ES supports queries on multiple indices, we're forced to have exactly same mapping. Are there any other options?

@clintongormley
Copy link
Contributor Author

terms filter already ignore missing fields so this works just fine. perhaps ask a question in the forum instead

@javanna javanna added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch
Projects
None yet
Development

No branches or pull requests

10 participants