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

Ensure that field collapsing works with field aliases. #50722

Merged
merged 1 commit into from
Jan 8, 2020

Conversation

jtibshirani
Copy link
Contributor

@jtibshirani jtibshirani commented Jan 8, 2020

Previously, the following situation would throw an error:

  • A search contains a collapse on a particular field.
  • The search spans multiple indices, and in one index the field is mapped as a
    concrete field, but in another it is a field alias.

The error occurs when we attempt to merge CollapseTopFieldDocs across shards.
When merging, we validate that the name of the collapse field is the same across
shards. But the name has already been resolved to the concrete field name, so it
will be different on shards where the field was mapped as an alias vs. shards
where it was a concrete field.

This PR updates the collapse field name in CollapseTopFieldDocs to the
original requested field, so that it will always be consistent across shards.

Note that in #32648, we already made a fix around collapsing on field aliases.
However, we didn't test this specific scenario (where the field was mapped
differently across indices).

Addresses #50121.

@jtibshirani jtibshirani added :Search Foundations/Mapping Index mappings, including merging and defining field types >bug v7.6.0 v8.0.0 labels Jan 8, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (:Search/Mapping)

Previously, the following situation would throw an error:
* A search contains a `collapse` on a particular field.
* The search spans multiple indices, and in one index the field is mapped as a
  concrete field, but in another it is a field alias.

The error occurs when we attempt to merge `CollapseTopFieldDocs` across shards.
When merging, we validate that the name of the collapse field is the same across
shards. But the name has already been resolved to the concrete field name, so it
will be different on shards where the field was mapped as an alias vs. shards
where it was a concrete field.

This PR updates the collapse field name in `CollapseTopFieldDocs` to the
original requested field, so that it will always be consistent across shards.

Note that in elastic#32648, we already made a fix around collapsing on field aliases.
However, we didn't test this specific scenario where the field was mapped as an
alias in only one of the indices being searched.
@jtibshirani jtibshirani marked this pull request as ready for review January 8, 2020 20:40
@jtibshirani
Copy link
Contributor Author

@jimczi would you be up for reviewing this? I am not completely sure about the approach and would be open to other suggestions.

Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

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

The approach looks good to me, the collapse field used in the top docs is part of the response so +1 to preserve the one provided by the user.

@jtibshirani jtibshirani merged commit 2dbaa65 into elastic:master Jan 8, 2020
@jtibshirani
Copy link
Contributor Author

Thanks for the review.

@jtibshirani jtibshirani deleted the collapse-with-alias branch January 8, 2020 21:50
jtibshirani added a commit that referenced this pull request Jan 9, 2020
Follow-up to #50722, which was also backported to 7.5 and 7.6.
SivagurunathanV pushed a commit to SivagurunathanV/elasticsearch that referenced this pull request Jan 23, 2020
Previously, the following situation would throw an error:
* A search contains a `collapse` on a particular field.
* The search spans multiple indices, and in one index the field is mapped as a
  concrete field, but in another it is a field alias.

The error occurs when we attempt to merge `CollapseTopFieldDocs` across shards.
When merging, we validate that the name of the collapse field is the same across
shards. But the name has already been resolved to the concrete field name, so it
will be different on shards where the field was mapped as an alias vs. shards
where it was a concrete field.

This PR updates the collapse field name in `CollapseTopFieldDocs` to the
original requested field, so that it will always be consistent across shards.

Note that in elastic#32648, we already made a fix around collapsing on field aliases.
However, we didn't test this specific scenario where the field was mapped as an
alias in only one of the indices being searched.
SivagurunathanV pushed a commit to SivagurunathanV/elasticsearch that referenced this pull request Jan 23, 2020
Follow-up to elastic#50722, which was also backported to 7.5 and 7.6.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Search Foundations/Mapping Index mappings, including merging and defining field types v7.5.2 v7.6.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants