-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Replace some usages of QueryShardContext#getMapperService #63239
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
Replace some usages of QueryShardContext#getMapperService #63239
Conversation
QueryShardContext a getter that allows to have access to the MapperService. In many cases, it is misused to lookup field types which QueryShardContext has a specific method for. This commit replaces those usages with a function String -> MappedFieldType .
Pinging @elastic/es-search (:Search/Mapping) |
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.
This is a nice cleanup! And I think we can clean up yet further...
I think we can remove the field type lookup entirely from LuceneChangesSnapshot
- it's used after we've loaded stored fields for a post-process step, but that step is done only to format numeric valued fields and the changes snapshot isn't looking at user-defined fields at all.
@@ -144,7 +144,7 @@ protected int doHashCode() { | |||
|
|||
@Override | |||
protected ScoreFunction doToFunction(QueryShardContext context) { | |||
MappedFieldType fieldType = context.getMapperService().fieldType(field); | |||
MappedFieldType fieldType = context.fieldMapper(field); |
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.
Maybe we should rename this fieldType
rather than fieldMapper
?
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.
yes indeed, I planned to do it as a follow-up
@@ -87,9 +87,9 @@ public Status needsField(FieldInfo fieldInfo) { | |||
: Status.NO; | |||
} | |||
|
|||
public void postProcess(MapperService mapperService) { | |||
public final void postProcess(Function<String, MappedFieldType> fieldTypeLookup) { |
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 do wonder if we can remove this step entirely, or replace it with the ValueFetcher functionality somehow - for a followup though.
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.
So this doesn't do anything to the _id
, _source
or _routing
fields, so I think we can remove the call to it entirely from LuceneChangesSnapshot
and possibly a few other places as well.
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.
ok I will look at it, possibly make this change in a separate PR then.
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.
++
run elasticsearch-ci/packaging-sample-windows |
@romseygeek I went ahead and adapted some more places, the PR got quite bigger though, could you have another look please? |
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.
LGTM, thanks @javanna
As part of elastic#63239 we have moved some usages of `QueryShardContext#getMapperService` that were looking up a field type through the `fieldType` method, to use the existing `QueryShardContext#fieldMapper`. The latter though has additional handling for unmapped fields when the functionality is enabled, and may throw exception if the field is not mapped. This additional behaviour is not desirable and may cause issues in cases where the callers have their own specific handling for situations where the field is not mapped. To address this we introduce an additional fieldType method to `QueryShardContext` that allows to simply look up a field type given its name. relates to elastic#63239
As part of #63239 we have moved some usages of QueryShardContext#getMapperService that were looking up a field type through the fieldType method, to use the existing QueryShardContext#fieldMapper. The latter though has additional handling for unmapped fields when the functionality is enabled, and may throw exception if the field is not mapped. This additional behaviour is not desirable and may cause issues in cases where the callers have their own specific handling for situations where the field is not mapped. To address this we introduce an additional isFieldMapped method to QueryShardContext that allows to check if a field is mapped or not. relates to #63239
) QueryShardContext has a getter that allows to have access to MapperService. In many cases, it is misused to lookup field types which QueryShardContext has a specific method for. This commit replaces those usages with a function String -> MappedFieldType. There are also a few other places where MapperService is retrieved to call methods that are also available directly on QueryShardContext, which are replaced as part of this commit too.
QueryShardContext has a getter that allows to have access to MapperService. In many cases, it is misused to lookup field types which QueryShardContext has a specific method for. This commit replaces those usages with a function String -> MappedFieldType. There are also a few other places where MapperService is retrieved to call methods that are also available directly on QueryShardContext, which are replaced as part of this commit too.
As part of elastic#63239 we have moved some usages of QueryShardContext#getMapperService that were looking up a field type through the fieldType method, to use the existing QueryShardContext#fieldMapper. The latter though has additional handling for unmapped fields when the functionality is enabled, and may throw exception if the field is not mapped. This additional behaviour is not desirable and may cause issues in cases where the callers have their own specific handling for situations where the field is not mapped. To address this we introduce an additional isFieldMapped method to QueryShardContext that allows to check if a field is mapped or not. relates to elastic#63239
As part of #63239 we have moved some usages of QueryShardContext#getMapperService that were looking up a field type through the fieldType method, to use the existing QueryShardContext#fieldMapper. The latter though has additional handling for unmapped fields when the functionality is enabled, and may throw exception if the field is not mapped. This additional behaviour is not desirable and may cause issues in cases where the callers have their own specific handling for situations where the field is not mapped. To address this we introduce an additional isFieldMapped method to QueryShardContext that allows to check if a field is mapped or not. relates to #63239
QueryShardContext
has a getter that allows to have access toMapperService
. In many cases, it is misused to lookup field types whichQueryShardContext
has a specific method for. This commit replaces those usages with a functionString
->MappedFieldType
.There are also a few other places where
MapperService
is retrieved to call methods that are also available directly onQueryShardContext
, which are replaced as part of this PR too.