-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Rewrite queries on unmapped fields as MatchNoDocsQueryBuilder #49254
Comments
Pinging @elastic/es-search (:Search/Search) |
Could I jump on this issue? Fairly new to elasticsearch. |
@ejmiers Sure, can you only focus on TermQueryBuilder for the first iteration of your PR, add me as a reviewer, and once I'm good with the approach for TermQueryBuilder we will generalize to other queries that need the same change like TermsQueryBuilder, MatchQueryBuilder and MultiMatchQueryBuilder? |
Hi @jpountz, I am having difficulty locating the rewrite() function referenced above. Could you point me in the right direction? |
Apologies @ejmiers I had to work on this as part of another change, so this issue should soon no longer be relevant. |
@jpountz Should this issue be closed then? |
#49713 aims at introducing a new constant_keyword field which, like _index, always rewrites queries to a MatchAllQueryBuilder or a MatchNoneQueryBuilder in order to skip shards in the can_match phase. This change introduces a new ConstantFieldType marker class that helps get this functionality with any field and not just _index. Since this change refactors rewrites, I also took it as an opportunity to adrress #49254: instead of returning the same queries you would get on a keyword field when a field is unmapped, queries get rewritten to a MatchNoDocsQueryBuilder. This change exposed a couple bugs, like the fact that the percolator doesn't rewrite queries at query time, or that the significant_terms aggregation doesn't rewrite its inner filter, which I fixed. Closes #49254
…ic#52486) Since this change refactors rewrites, I also took it as an opportunity to adrress elastic#49254: instead of returning the same queries you would get on a keyword field when a field is unmapped, queries get rewritten to a MatchNoDocsQueryBuilder. This change exposed a couple bugs, like the fact that the percolator doesn't rewrite queries at query time, or that the significant_terms aggregation doesn't rewrite its inner filter, which I fixed. Closes elastic#49254
Generalize how queries on `_index` are handled at rewrite time (#52486) Since this change refactors rewrites, I also took it as an opportunity to adrress #49254: instead of returning the same queries you would get on a keyword field when a field is unmapped, queries get rewritten to a MatchNoDocsQueryBuilder. This change exposed a couple bugs, like the fact that the percolator doesn't rewrite queries at query time, or that the significant_terms aggregation doesn't rewrite its inner filter, which I fixed. Closes #49254
It's probably more easily explained with an example:
TermQueryBuilber#doToQuery
looks like this todaySo if the field is unmapped, we create a TermQuery on a field that doesn't exist, which is no different from returning a MatchNoDocsQuery.
It's becoming more and more common that multiple indices that have different mappings get queried together, e.g. as part of an alias or an index pattern, so a more efficient way to handle these cases would be to rewrite to a
MatchNoDocsQueryBuilder
in therewrite()
method. This would help figure out that the shard cannot possibly match in thecan_match
phase and skip thequery
phase completely.The text was updated successfully, but these errors were encountered: