Skip to content

Client version 8.2.2 does not build correct search request with runtime_mappings #298

Closed
@sothawo

Description

@sothawo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: SpecificationRelated to the API spec used to generate client code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions