Skip to content

Conversation

@javanna
Copy link
Member

@javanna javanna commented Mar 22, 2021

So far the runtime section supports only leaf field types, hence the internal representation is based on RuntimeFieldType that extends directly MappedFieldType. This is straightforward but it is limiting for e.g. an alias field that points to another field, or for object fields that are not queryable directly, hence should not be a MappedFieldType, yet their subfields do.

This commit makes RuntimeFieldType an interface, effectively splitting the definition of a runtime fields as defined and returned in the mappings, from its internal representation in terms of MappedFieldType.

The existing runtime script field types still extend MappedFieldType and now also implements the new interface, which makes the change rather simple.

So far the runtime section supports only leaf field types, hence the internal representation is based on `RuntimeFieldType` that extends directly `MappedFieldType`. This is straightforward but it is limiting for e.g. an alias field that points to another field, or for object fields that are not queryable directly, hence should not be a MappedFieldType, yet their subfields do.

This commit makes `RuntimeFieldType` an interface, effectively splitting the definition of a runtime fields as defined and returned in the mappings, from its internal representation in terms of `MappedFieldType`.

The existing runtime script field types still extend `MappedFieldType` and now also implements the new interface, which makes the change rather simple.
@javanna javanna added :Search Foundations/Mapping Index mappings, including merging and defining field types >refactoring v8.0.0 v7.13.0 labels Mar 22, 2021
@javanna javanna requested a review from romseygeek March 22, 2021 21:07
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Mar 22, 2021
@elasticmachine
Copy link
Collaborator

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

* A Builder for a ParametrizedFieldMapper
*/
public abstract static class Builder extends Mapper.Builder {
public abstract static class Builder extends Mapper.Builder implements ToXContentFragment {
Copy link
Member Author

Choose a reason for hiding this comment

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

this is not extremely important, at the same time I got frustrated that we were carrying around a CheckedBiConsumer while we have a commonly used interface for this sort of things. This change allows carrying a ToXContent instance instead in the different script field types

super(name, false, false, false, TextSearchInfo.SIMPLE_MATCH_WITHOUT_TERMS, meta);
this.toXContent = toXContent;
}
public interface RuntimeFieldType extends ToXContentFragment {
Copy link
Member Author

Choose a reason for hiding this comment

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

@romseygeek looks familiar? :) I did take inspiration from your previous proposal around aliases as runtime fields.

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 would propose renaming this to RuntimeField in a follow-up

* Exposes the {@link MappedFieldType} backing this runtime field, used to execute queries, run aggs etc.
* @return the {@link MappedFieldType} backing this runtime field
*/
MappedFieldType asMappedFieldType();
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 envision this returning a Collection once we introduce the object runtime field

MappedFieldType fieldType = runtimeFieldType.asMappedFieldType();
runtimeFieldTypes.put(fieldType.name(), fieldType);
}
return Collections.unmodifiableMap(runtimeFieldTypes);
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 was thinking that maybe we should make FieldTypeLookup public and use it in SearchExecutionContext instead of reproducing its behavour with the runtime fields defined in the search request

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.

What a great idea, who thought of this? :)

LGTM.

@javanna javanna merged commit edb4269 into elastic:master Mar 23, 2021
javanna added a commit to javanna/elasticsearch that referenced this pull request Mar 23, 2021
)

So far the runtime section supports only leaf field types, hence the internal representation is based on `RuntimeFieldType` that extends directly `MappedFieldType`. This is straightforward but it is limiting for e.g. an alias field that points to another field, or for object fields that are not queryable directly, hence should not be a MappedFieldType, yet their subfields do.

This commit makes `RuntimeFieldType` an interface, effectively splitting the definition of a runtime fields as defined and returned in the mappings, from its internal representation in terms of `MappedFieldType`.

The existing runtime script field types still extend `MappedFieldType` and now also implement the new interface, which makes the change rather simple.
javanna added a commit that referenced this pull request Mar 23, 2021
…70715)

So far the runtime section supports only leaf field types, hence the internal representation is based on `RuntimeFieldType` that extends directly `MappedFieldType`. This is straightforward but it is limiting for e.g. an alias field that points to another field, or for object fields that are not queryable directly, hence should not be a MappedFieldType, yet their subfields do.

This commit makes `RuntimeFieldType` an interface, effectively splitting the definition of a runtime fields as defined and returned in the mappings, from its internal representation in terms of `MappedFieldType`.

The existing runtime script field types still extend `MappedFieldType` and now also implement the new interface, which makes the change rather simple.
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.13.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants