Fix redundant assignment in QueryStringQueryBuilder #119775
Merged
+12
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have a redundant assignment in
QueryStringQueryBuilder
forextractedFields
:elasticsearch/server/src/main/java/org/elasticsearch/index/search/QueryStringQueryParser.java
Lines 268 to 282 in 82b1f2a
To fix this we can remove the
extractedFields = fieldsAndWeights
assignment altogether.However
fieldsAndWeights
already contains the same result of the second assignment.fieldsAndWeights
is actually initialised with the exact same value (when the redundant assignment is executed) - see the call toresolveMappingField
:elasticsearch/server/src/main/java/org/elasticsearch/index/search/QueryStringQueryParser.java
Lines 132 to 134 in 82b1f2a
When matching all fields I think it was always the intention to just reuse
fieldsAndWeights
, but the redundant assignment and extra computation was added as a regression in #55158In the context of a single
query_string
execution,extractMultiFields
can be called multiple times. Some examples where the redundant assignment is triggered and we end up extracting the fields for wildcard queries multiple times:something OR nothing OR anything
- 3 redundant assignments and recomputing the available fields, instead of relying on the storedfieldsAndWeights
.*:something AND nothing
- 2 redundant assignmentsThis is why I decided to keep the
extractedFields = fieldsAndWeights
assignment and just to make sure we don't callresolveMappingField
unnecessarily.