OpenSearch Java client does not support 'flat_object' field type properly

Hi everyone,

I would appreciate any help with the following issue (workaround, bug confirmation etc.). Thanks!

I cannot use the java client to create an index with a mapping for a flat_object property. I am using the latest client (opensearch-java: 2.8.0) and server code (OpenSearch server: 2.11.0). I tried the following simple code:

    final CreateIndexRequest createIndexRequest
        = new CreateIndexRequest.Builder()
        .mappings(m ->"sample_property", Property.of(p -> p.flattened(new FlattenedProperty.Builder().build()))))
    final CreateIndexResponse createIndexResponse
        = client.indices().create(createIndexRequest);

which results in the following error:

org.opensearch.client.opensearch._types.OpenSearchException: Request failed: [mapper_parsing_exception] Failed to parse mapping [_doc]: No handler for type [flattened] declared on field [sample_property]

Interestingly, the Java client (and generated JSON payload) use the name ‘flattened’ for the field type, which is the ElasticSearch name for its version of the flat_object field type (Flattened field type | Elasticsearch Guide [8.11] | Elastic). If I execute the corresponding REST command in Dashboards and change the field type from ‘flattened’ to ‘flat_object’, it works (though the autocomplete does not suggest ‘flat_object’, as it does for other field types):

PUT /sample_index
  "mappings" : {
    "properties" : {
      "sample_property" : {
        "type" : "flat_object"

I think this is a bug in the client. Unfortunately, I have not been able to find a workaround in the Java client which allows me to replace ‘flattened’ with ‘flat_object’.

Hey @JoeCo , could you please open an issue here Issues · opensearch-project/opensearch-java · GitHub with the request to support the flat_object field type? Thank you.

Hi @reta ,

Thank you for the response. I filed a feature request: [FEATURE] Support flat_object field type in Java client · Issue #720 · opensearch-project/opensearch-java · GitHub

In case anyone else has the same issue… I found a temporary workaround by using the lower level RestClient (from opensearch-rest-client) using raw JSON to make the create index request with the flat_object field type:

    final Request request = new Request("PUT", "/" + indexName);
    request.setJsonEntity("{\n" +
        "  \"mappings\" : {\n" +
        "    \"properties\" : {\n" +
        "      \"sample_property\" : {\n" +
        "        \"type\" : \"flat_object\"\n" +
        "      }\n" +
        "    }\n" +
        "  }\n" +
    final Response response = restClient.performRequest(request);