How to create a MappingType for a property with multi-fields in OpenSearch Java Client

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):

OpenSearch Java Client 2.x

Describe the issue:
I am trying to create a index that has multi-fields using opensearch Java Client. I couldn’t find a way to specify this.

For example, in the following mappings property “city” has “keyword” field that has “keyworkd” type.

  "mappings": {
    "properties": {
      "city": {
        "type": "text",
        "fields": {
          "keyword": { 
            "type":  "keyword"
          }
        }
      }
    }
  }

I don’t know how to add “keyword” fields to the TypeMapping in OpenSearch Java Client:


    TypeMapping mappings = new TypeMapping.Builder()
                              .properties("city", new Property.Builder().text(new TextProperty.Builder().build()).build()) ...  
                              .build()

Thanks for any help.

Configuration:

Relevant Logs or Screenshots:

1 Like

In the latest version for both OpenSearch and its Dashboards(2.15.0 for now), multi-fields property is not supported in the Visual editor.

But you can still specify index mapping using JSON Editor(link). I think one day contributors in OpenSearch Dashboards will bring new feature(like Kibana) into Dashboards.

In addition, not only multi-fields property can be mapped in templates, but also k-NN vector, Percolator, Derived type can be.