Skip to content

Conversation

@romseygeek
Copy link
Contributor

In 6x and 7x, indexes can have only one type, which means that we can rework
all queries against the type field to use a ConstantFieldType. This has already
been done in master with the removal of the TypeFieldMapper, but we still need
that class in 7x to deal with nested documents. This commit leaves
TypeFieldMapper in place, but refactors TypeFieldType to extend
ConstantFieldType and consolidates deprecation warnings within that class.

It also incidentally removes the requirement to pass a MapperService to
IndexFieldData.Builder#build, which should allow #63197 to be backported.

@romseygeek romseygeek added :Search Foundations/Mapping Index mappings, including merging and defining field types >refactoring v7.10.0 labels Oct 3, 2020
@romseygeek romseygeek requested a review from javanna October 3, 2020 08:41
@romseygeek romseygeek self-assigned this Oct 3, 2020
@elasticmachine
Copy link
Collaborator

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

@elasticmachine elasticmachine added the Team:Search Meta label for search team label Oct 3, 2020
if (fullName.equals(TypeFieldMapper.NAME)) {
String type = mapper == null ? null : mapper.type();
return new TypeFieldMapper.TypeFieldType(type);
}
Copy link
Member

Choose a reason for hiding this comment

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

for my understanding: does this mean that the field type does not come back with the below field type lookup? Did it before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does come back with the lookup, but it may not have the correct type set on it (for example, if the index in question did not have any mappings set when the MapperService was originally built). This way we know we always have the correct type.

Copy link
Member

Choose a reason for hiding this comment

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

ok, so could there be places where the type field mapper is retrieved in some way that could expose the wrong type then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From a quick review:

  • the only other way to access field types is via MapperService#documentMapper#fieldTypes() directly
  • this is exposed via MapperService#fieldTypes()
  • MapperService#fieldTypes() is only called by the index warming code, and the type field does not use global ordinals so is unaffected

So I think we're safe. We should probably remove MapperService#fieldTypes() at some point though, as it is indeed asking for trouble to expose this to the outside world.

Copy link
Member

Choose a reason for hiding this comment

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

ok thanks for double checking

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for keeping me honest :)

Copy link
Member

@javanna javanna left a comment

Choose a reason for hiding this comment

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

LGTM thanks @romseygeek !

@romseygeek romseygeek merged commit 7405af8 into elastic:7.x Oct 6, 2020
@romseygeek romseygeek deleted the typefieldtype-7x branch October 6, 2020 09:27
romseygeek added a commit that referenced this pull request Oct 7, 2020
#63214 made TypeFieldType a constant field, and fixed things so that it always
emits deprecation warnings whenever it is referenced in a query or aggregation.
However, it also emits warnings when it is used to build a type filter through
the search context; this is unnecessary, as warnings are already emitted by
the REST layer when types are specified as part of the URL, and it is causing
failures in some BWC tests.

This commit adds a specialised typeFilter method to TypeFieldType to handle
this case without emitted any extra warnings. It also removes an unused duplicate
TypeFieldType class that resulted from a backport merge error.

Fixes #63366
romseygeek added a commit that referenced this pull request Oct 7, 2020
#63214 made TypeFieldType a constant field, and fixed things so that it always
emits deprecation warnings whenever it is referenced in a query or aggregation.
However, it also emits warnings when it is used to build a type filter through
the search context; this is unnecessary, as warnings are already emitted by
the REST layer when types are specified as part of the URL, and it is causing
failures in some BWC tests.

This commit adds a specialised typeFilter method to TypeFieldType to handle
this case without emitted any extra warnings. It also removes an unused duplicate
TypeFieldType class that resulted from a backport merge error.

Fixes #63366
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.10.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants