Insert object to nested array

Viewed 182

I'm trying to insert an object to a nested array through the java api, but I get the following error

MapperParsingException[object mapping for [X] tried to parse field [null] as object, but found a concrete value]

doing it through Kibana as shown below the same script works.

Any ideas on how to fix this?

The java code is the following

HashMap<String, Object> params = new HashMap<>();
params.put("object", objectAsString);
Script script = new Script(ScriptType.INLINE, "painless", "ctx._source.media.add(params.object)", params);
UpdateResponse result = elasticClient.prepareUpdate(indexName, "Type", documentId).setScript(script).execute().actionGet();

Trhough Kibana

POST index/document/id/_update
{
   "script": {
      "lang": "painless",
      "inline": "ctx._source.media.add(params.object)",
      "params": {
         "object": {
           "description" : "A second image",
      "height" :  5,
      "weight": 5,
      "name" :  "Test",
      "orientation" :  "Vertical",
       "url" :  "htttp://newurl.jpg",
      "tags":["first","second"],
      "type":"image"
         }
      }
   }
}

The template mapping is the following:

"mappings": {
        "FOLDER_MODULE": {
            "properties": {
                "name": {
                    "type": "keyword"
                },
                "publisherId": {
                    "type": "keyword"
                },
                "username": {
                    "type": "keyword"
                },
                "media": {
                    "type": "nested",
                    "properties": {
                        "id": {
                            "type": "text"
                        },
                        "name": {
                            "type": "text"
                        },
                        "publisherId": {
                            "type": "short"
                        },
                        "tags": {
                            "type": "text"
                        },
                        "description": {
                            "type": "text"
                        },
                        "url": {
                            "type": "keyword"
                        },
                        "createdDate": {
                            "format": "strict_date_optional_time||epoch_millis",
                            "type": "date"
                        },
                        "height": {
                            "type": "float"
                        },
                        "width": {
                            "type": "float"
                        },
                        "weight": {
                            "type": "float"
                        },
                        "orientation": {
                            "type": "keyword"
                        },
                        "status": {
                            "type": "keyword"
                        },
                        "type": {
                            "type": "keyword"
                        },
                        "username": {
                            "type": "keyword"
                        }
                    }
                }
            }
        }
    }
0 Answers
Related