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

Fix index prefixes to work with span_multi #31066

Merged
merged 3 commits into from
Jun 4, 2018

Conversation

jimczi
Copy link
Contributor

@jimczi jimczi commented Jun 4, 2018

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

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
@jimczi jimczi added >bug :Search/Search Search-related issues that do not fall into other categories v7.0.0 v6.4.0 labels Jun 4, 2018
@jimczi jimczi requested review from jpountz and romseygeek June 4, 2018 12:27
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

Copy link
Contributor

@jpountz jpountz left a 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) {
Copy link
Contributor

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());
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 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());
Copy link
Contributor

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)) {
Copy link
Contributor

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?

Copy link
Contributor

@romseygeek romseygeek left a 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);
Copy link
Contributor

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?

@jimczi jimczi merged commit f94a757 into elastic:master Jun 4, 2018
@jimczi jimczi deleted the prefixes_span_multi branch June 4, 2018 19:49
dnhatn added a commit that referenced this pull request Jun 4, 2018
* master:
  Add get mappings support to high-level rest client (#30889)
  Fix index prefixes to work with span_multi (#31066)
  [DOCS] Removes redundant authorization pages
  [DOCS] Re-adds custom realm
  Change ObjectParser exception (#31030)
  Upgrade to Lucene-7.4.0-snapshot-0a7c3f462f (#31073)
jimczi added a commit that referenced this pull request Jun 5, 2018
* 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
jimczi added a commit that referenced this pull request Jun 5, 2018
martijnvg added a commit that referenced this pull request Jun 5, 2018
* 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)
jimczi added a commit that referenced this pull request Jun 5, 2018
multi_span prefix queries do not work with the prefix field
before 6.4.

Relates #31066
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 v6.4.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make index_prefixes work with span_multi
5 participants