question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Client version 8.2.2 does not build correct search request with `runtime_mappings`

See original GitHub issue

Java 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:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
swallezcommented, Aug 22, 2022

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.

0reactions
sothawocommented, Sep 19, 2022

Any info when this will be released?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found