How to write json array to elasticsearch's objetct field by es rest client?

I use elasticsearch6.8 and jdk8. The key problem is hot to write json array string to elasticsearch's object type field. Following code show how I tried to write to es.

My mapping is as follows:
{ "mapping": { "_doc": { "properties": { "c_json": { "type": "object" } } } } }

My c_json value is :

{ "key1": "val1", "key2": "val2", "key3": "val3" }

My java code is :

String json="{
  "key1": "val1",
  "key2": "val2",
  "key3": "val3"
String keyName="c_json";
Map<String,String> myDataMap = new HashMap();

IndexRequest indexRequest = new IndexRequest("my_index").id(esIdValue)
           BulkRequest bulkRequest = new BulkRequest();
            BulkResponse bulkResponse = es6Client.bulk(bulkRequest, RequestOptions.DEFAULT);

    public static Object[] convertMapToEsValues(Map<String, Object> valueMap) {
        List<Object> kvList = Lists.newArrayList();
        for (String fieldName : valueMap.keySet()) {
        return kvList.toArray();

When I run the code, es server give me the exception:
ElasticsearchException[Elasticsearch exception [type=mapper_parsing_exception, reason=object mapping for [c_json] tried to parse field [c_json] as object, but found a concrete value]],action id is 9, Index name is my_index

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.