-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Teach _search to read search time mappings #59316
Teach _search to read search time mappings #59316
Conversation
This adds support for search time mappings to the _search API like so: ``` curl -XPOST -HContent-Type:application/json -uelastic:password 'localhost:9200/test/_search?pretty&error_trace' -d'{ "mappings": { "properties": { "cat": { "type": "script", "runtime_type": "keyword", "script": "value(\"cat\")" } } }, "docvalue_fields": ["cat"] }' ``` It just lifts the `mappings` field from the create index and mappings update requests and drops it into the `_search` request. It then gives each mapped field a chance to convert itself into a runtime field. Most mapping can not and will throw an exception that is translated into an HTTP 400 response. The `script` converts itself properly and is available at runtime.
@javanna and I talked about changing it to just |
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 left some comments, I guess one thing to look at is whether we could parse/validate the new section in the coordinating node so that we could fail early and once if something is wrong or if a non-runtime field is defined as part of the search request. Could we also validate the script once? I'm afraid it will be tough because MapperService is an index component, but there may be other ways to only validate?
@@ -239,6 +244,9 @@ public SearchSourceBuilder(StreamInput in) throws IOException { | |||
sliceBuilder = in.readOptionalWriteable(SliceBuilder::new); | |||
collapse = in.readOptionalWriteable(CollapseBuilder::new); | |||
trackTotalHitsUpTo = in.readOptionalInt(); | |||
if (in.getVersion().onOrAfter(Version.V_8_0_0)) { |
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.
add a TODO to update the version once the branch is merged?
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.
👍
if (out.getVersion().onOrAfter(Version.V_8_0_0)) { | ||
out.writeMap(extraMapping); | ||
} else { | ||
throw new IllegalArgumentException( |
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.
why throw exception? shouldn't we rather not write the map, and that's it?
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.
If we don't write the map then nodes that can't understand will silently ignore the fields which feels bad!
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.
oh true, so only some nodes may have the runtime fields which messes up the results? This is pretty important indeed. I wonder what effect does throwing here makes from a user's point of view.
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.
also is not completely the truth. it depends on the nodes that get hit?
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.
The last I checked it'll cause the request to 400
with the message. It does depend on which node gets hit, yeah.
I think it'll also come up in CCS where I expect the remote cluster could be at an older version for longer. I'll update the error message a little.
server/src/main/java/org/elasticsearch/index/mapper/MapperService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/mapper/MapperService.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/query/QueryShardContext.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/search/fetch/subphase/FetchDocValuesPhase.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/mapper/Mapper.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/query/QueryShardContext.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/mapper/MapperService.java
Outdated
Show resolved
Hide resolved
Just added an integration test! Yay! |
Pinging @elastic/es-search (:Search/Search) |
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 left some comments/questions
server/src/main/java/org/elasticsearch/index/mapper/Mapper.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/mapper/MapperService.java
Outdated
Show resolved
Hide resolved
Mapper.Builder<?> builder = parser.parse(runtimeEntry.getKey(), definition, documentMapperParser().parserContext()); | ||
Mapper mapper = builder.build(builderContext); | ||
|
||
MapperUtils.collect(mapper, objectMappers, fieldMappers, fieldAliasMappers); |
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.
Can you expand on why we need this? I was expecting that alias or objects would be caught anyways by your checks below, that only runtime fields can be defined.
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 should allow us to collect the sub-mappers under objects. I do need to make sure there is a test for though.
I marked this stalled as we decided to postpone allowing to define runtime fields as part of the search request. We will get back to this later. |
This adds support for search time mappings to the _search API like so:
It just lifts the
mappings
field from the create index and mappingsupdate requests and drops it into the
_search
request. It then giveseach mapped field a chance to convert itself into a runtime field. Most
mapping can not and will throw an exception that is translated into an
HTTP 400 response. The
script
converts itself properly and isavailable at runtime.
Relates to #59332