Skip to content

Add isFieldMapped method to QueryShardContext #63322

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

Merged

Conversation

javanna
Copy link
Member

@javanna javanna commented Oct 6, 2020

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

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
@javanna javanna added :Search Foundations/Mapping Index mappings, including merging and defining field types >refactoring v8.0.0 v7.10.0 labels Oct 6, 2020
@javanna javanna requested a review from romseygeek October 6, 2020 12:26
@elasticmachine
Copy link
Collaborator

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

@elasticmachine elasticmachine added the Team:Search Meta label for search team label Oct 6, 2020
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.

LGTM

@@ -231,6 +231,10 @@ public MappedFieldType fieldMapper(String name) {
return failIfFieldMappingNotFound(name, mapperService.fieldType(name));
}

public MappedFieldType fieldType(String name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we put some javadocs on here, specifically around the fact that it may return null?

Copy link
Contributor

Choose a reason for hiding this comment

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

Too fast! Can you add a note about null?

@@ -90,10 +90,6 @@ public Status needsField(FieldInfo fieldInfo) {
public final void postProcess(Function<String, MappedFieldType> fieldTypeLookup) {
for (Map.Entry<String, List<Object>> entry : fields().entrySet()) {
MappedFieldType fieldType = fieldTypeLookup.apply(entry.getKey());
if (fieldType == null) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I moved this logic to the caller, it is now part of the lookup function that is provided.

@javanna javanna changed the title Add fieldType method to QueryShardContext Add isFieldMapped method to QueryShardContext Oct 6, 2020
@javanna javanna requested a review from romseygeek October 6, 2020 15:24
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.

Much nicer, thanks @javanna

@javanna javanna merged commit b21b79d into elastic:master Oct 7, 2020
javanna added a commit to javanna/elasticsearch that referenced this pull request Oct 12, 2020
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
javanna added a commit that referenced this pull request Oct 12, 2020
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>refactoring :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Meta label for search team v7.11.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants