Skip to content

Rename QueryShardContext#fieldMapper to getFieldType #63399

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

Conversation

javanna
Copy link
Member

@javanna javanna commented Oct 7, 2020

Given that we have a class called FieldMapper and that the fieldMapper method exposed by QueryShardContext actually allows to get a MappedFieldType given its name, this commit renames such method to getFieldType

Given that we have a class called `FieldMapper` and that the `fieldMapper` method exposed by `QueryShardContext` actually allows to get a `MappedFieldType` given its name, this commit renames such method to `getFieldType`
@javanna javanna added :Search Foundations/Mapping Index mappings, including merging and defining field types >refactoring v8.0.0 v7.11.0 labels Oct 7, 2020
@javanna javanna requested a review from romseygeek October 7, 2020 12:27
@elasticmachine
Copy link
Collaborator

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

@elasticmachine elasticmachine added the Team:Search Meta label for search team label Oct 7, 2020
@@ -108,7 +108,7 @@ public String getWriteableName() {

@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
MappedFieldType fieldType = context.fieldMapper(field);
MappedFieldType fieldType = context.getFieldType(field);
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 find some of these usages suspicious: do they really mean to check if the returned field type is null after the unmapped fields handling (unmapped fields may get mapped as text), or would they rather need to call isFieldMapped ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure these should be calling isFieldMapped. We should maybe think about moving the unmapped field handling out of QueryShardContext and have it at the callsites that really need it? It's a bit too magic otherwise.

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 think we need to review all the ==null checks, but let's do it in a separate PR to keep the rename clear.

@@ -108,7 +108,7 @@ public String getWriteableName() {

@Override
protected Query doToQuery(QueryShardContext context) throws IOException {
MappedFieldType fieldType = context.fieldMapper(field);
MappedFieldType fieldType = context.getFieldType(field);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm pretty sure these should be calling isFieldMapped. We should maybe think about moving the unmapped field handling out of QueryShardContext and have it at the callsites that really need it? It's a bit too magic otherwise.

@@ -152,7 +152,7 @@ public static FieldMaskingSpanQueryBuilder fromXContent(XContentParser parser) t
@Override
protected SpanQuery doToQuery(QueryShardContext context) throws IOException {
String fieldInQuery = fieldName;
MappedFieldType fieldType = context.fieldMapper(fieldName);
MappedFieldType fieldType = context.getFieldType(fieldName);
if (fieldType != null) {
fieldInQuery = fieldType.name();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Basically everywhere that does this null check should be calling isMapped instead.

@@ -147,7 +147,7 @@ public IntervalsSource getSource(QueryShardContext context, MappedFieldType fiel
}
IntervalsSource source;
if (useField != null) {
fieldType = context.fieldMapper(useField);
fieldType = context.getFieldType(useField);
assert fieldType != null;
Copy link
Contributor

Choose a reason for hiding this comment

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

These assertions look dodgy (I think I put them in in the first place, so I'm allowed to say that). It should be throwing an error if passed a field that doesn't exist or doesn't support text searches.

@javanna
Copy link
Member Author

javanna commented Oct 7, 2020

run elasticsearch-ci/2

@javanna javanna merged commit 95582da into elastic:master Oct 7, 2020
javanna added a commit to javanna/elasticsearch that referenced this pull request Oct 12, 2020
Given that we have a class called `FieldMapper` and that the `fieldMapper` method exposed by `QueryShardContext` actually allows to get a `MappedFieldType` given its name, this commit renames such method to `getFieldType`
javanna added a commit that referenced this pull request Oct 12, 2020
Given that we have a class called `FieldMapper` and that the `fieldMapper` method exposed by `QueryShardContext` actually allows to get a `MappedFieldType` given its name, this commit renames such method to `getFieldType`
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