Client version 8.2.2 does not build correct search request with `runtime_mappings`
See original GitHub issueJava API client version
8.2.2
Java version
17.0.3
Elasticsearch Version
8.2.2
Problem description
The following code stores a document and then should do a search with a runtime_mappings
field:
ElasticsearchClient client = createTheClient();
String index = "testindex";
var p = new Product("p1", 42.0);
client.index(ir -> ir
.index(index)
.document(p));
client.indices().flush(f -> f.index(index));
RuntimeField runtimeField = RuntimeField.of(rf -> rf
.type(RuntimeFieldType.Double)
.script(Script.of(s -> s
.inline(i -> i.
source("emit(doc['price'].value * 1.19)")
)
))
);
client.search(sr -> sr
.index(index)
.runtimeMappings("priceWithTax", Collections.singletonList(runtimeField)), // NOTE: the builder accepts only lists here
Person.class);
The request that is sent to Elasticsearch has the following body:
{
"runtime_mappings": {
"priceWithTax": [
{
"script": {
"source": "emit(doc['price'].value * 1.19)"
},
"type": "double"
}
]
}
}
Note that the priceWithTax
property is an array, the client builder requires a list here.
This request leads to an error response from the server:
{
"error" : {
"root_cause" : [
{
"type" : "mapper_parsing_exception",
"reason" : "Expected map for runtime field [priceWithTax] definition but got a java.util.ArrayList"
}
],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [
{
"shard" : 0,
"index" : "testindex",
"node" : "ef-uEMwKS1mbgKHO-Gz3mg",
"reason" : {
"type" : "mapper_parsing_exception",
"reason" : "Expected map for runtime field [priceWithTax] definition but got a java.util.ArrayList"
}
}
]
},
"status" : 400
}
Neither the documentation for runtime_fields in a search request nor for runtime_fields in a mapping specify this as an array.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Define runtime fields in a search request - Elastic
The duration runtime field doesn't exist in the index mapping, but we can still search and aggregate on that field. The following query...
Read more >[Transform] Add support for search-time runtime fields. (#67643)
Defaults to MatchAll query. * @param runtimeMappings Search-time runtime fields that can be used by the transform.
Read more >Spring Data Elasticsearch - Reference Documentation
The Elasticsearch version given shows with which client libraries Spring ... If the repository infrastructure does not find a declared query ...
Read more >Node and elasticSearch client - The client noticed that the ...
Basically, all Elastic clients are going to be updated to not work with anything else than official Elastic versions: ...
Read more >Client Installation | Socket.IO
JS Client version, Socket. ... If you don't need this (see other options below), you can disable the functionality on the server side:....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
runtime_mappings
is incorrectly defined in the spec as a map of either a single mapping or an array of mappings when it should really be a map of single mappings. Fix in progress.Any info when this will be released?