-
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
Fix index prefixes to work with span_multi #31066
Conversation
Text fields that use `index_prefixes` can rewrite `prefix` queries into `term` queries internally. This commit fix the handling of this rewriting in the `span_multi` query. This change also copies the index options of the text field into the prefix field in order to be able to run positional queries. This is mandatory for `span_multi` to work but this could also be useful to optimize `match_phrase_prefix` queries in a follow up. Note that this change can only be done on indices created after 6.3 since we set the index options to doc only in this version. Fixes elastic#31056
Pinging @elastic/es-search-aggs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some minor comments, looks good in general. Thanks @jimczi.
if (subQuery instanceof BoostQuery) { | ||
if (subQuery instanceof ConstantScoreQuery) { | ||
subQuery = ((ConstantScoreQuery) subQuery).getQuery(); | ||
} else if (subQuery instanceof BoostQuery) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we unwrap recursively to be more resilient to changes to the way queries are built?
*/ | ||
if (multiTermQueryBuilder.getClass() != PrefixQueryBuilder.class) { | ||
throw new UnsupportedOperationException("unsupported inner query, should be " | ||
+ MultiTermQuery.class.getName() + " but was " + subQuery.getClass().getName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's include the class of multiTermQueryBuilder to the error message as well?
// Copy the index options of the main field to allow phrase queries on | ||
// the prefix field. | ||
if (context.indexCreatedVersion().onOrAfter(Version.V_7_0_0_alpha1)) { | ||
prefixFieldType.setIndexOptions(fieldType.indexOptions()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we map DOCS_AND_FREQS
TO DOCS
?
if (fieldType.indexOptions() == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) { | ||
// Copy the index options of the main field to allow phrase queries on | ||
// the prefix field. | ||
if (context.indexCreatedVersion().onOrAfter(Version.V_7_0_0_alpha1)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can already be set to 6_4 before the backport, can't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left one comment, but looks good otherwise
@@ -339,7 +344,6 @@ public Query existsQuery(QueryShardContext context) { | |||
PrefixFieldType(String name, int minChars, int maxChars) { | |||
setTokenized(true); | |||
setOmitNorms(true); | |||
setIndexOptions(IndexOptions.DOCS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still need this? What happens with a 6.3 index that doesn't store offsets?
* Fix index prefixes to work with span_multi Text fields that use `index_prefixes` can rewrite `prefix` queries into `term` queries internally. This commit fix the handling of this rewriting in the `span_multi` query. This change also copies the index options of the text field into the prefix field in order to be able to run positional queries. This is mandatory for `span_multi` to work but this could also be useful to optimize `match_phrase_prefix` queries in a follow up. Note that this change can only be done on indices created after 6.3 since we set the index options to doc only in this version. Fixes #31056
* es/6.x: Fix compil after backport Fix index prefixes to work with span_multi (#31066) Delete superfluous UpdateRequest test Disable MultiMatchQueryBuilderTests. Disable UpdateRequestTest#testUnknownFieldParsing. Update get.asciidoc (#31084) When the 'strict' mapping option is enabled, make sure to validate split_queries_on_whitespace. Transport client: Don't validate node in handshake (#30737) (#31080) In the internal highlighter APIs, use the field type as opposed to the mapper. (#31039) [DOCS] Removes redundant authorization pages Upgrade to Lucene-7.4.0-snapshot-0a7c3f462f (#31073)
multi_span prefix queries do not work with the prefix field before 6.4. Relates #31066
Text fields that use
index_prefixes
can rewriteprefix
queries intoterm
queries internally. This commit fix the handling of this rewritingin the
span_multi
query.This change also copies the index options of the text field into the
prefix field in order to be able to run positional queries. This is mandatory
for
span_multi
to work but this could also be useful to optimizematch_phrase_prefix
queries in a follow up. Note that this change can only be done on indices created
after 6.3 since we set the index options to doc only in this version.
Fixes #31056