Update Nested object with logstash


(Michael Oullion) #1

Hello,

I spend the whole day reading and trying to update partial object with nested object.

First, I define a mapping :

"Info": {
          "type": "nested", 
          "properties": {
            "InfoName": {
				"type": "text", 
				"fields": {
					"raw": { 
						"type": "keyword"
					}
				}
        	},
            "Value": {
				"type": "text", 
				"fields": {
					"raw": { 
						"type": "keyword"
					}
				}
        	}
          }
        }

then I post 2 messages with Update API :
http://xxxxxxx:9200/xboud/document/1/_update

{
 	"scripted_upsert":true,
    "script" : {
        "inline": "if(ctx._source.Info == null){ctx._source.Info = []} ctx._source.Info.add(params.tag) ",
        "lang": "painless",
        "params" : {
            "tag" : {"InfoName":"green", "Value":"valeur"}
        }
    },
    "upsert" : {}
}

I get what I want :

{
    "_index": "xboud",
    "_type": "document",
    "_id": "1",
    "_version": 6,
    "found": true,
    "_source": {
        "Info": [
            {
                "Value": "valeur",
                "InfoName": "green"
            },
            {
                "Value": "valeur2",
                "InfoName": "green2"
            }
        ]
    }
}

Now,
I can't find a way to do this with logstash....
My last try was :

elasticsearch
			{	
				hosts => ["xxxx.corp.lan:9200"] 
				index => "xbound"
				action => "update"
				document_id => "%{docid}"
				document_type => "document"
				script => 'if(ctx._source.Info == null){ctx._source.Info = []} ctx._source.Info.add("%{temp}")'
				doc_as_upsert => true
			}

but I get the exception :
java.lang.IllegalArgumentException: Missing Ruby class handling for full class name=java.util.HashMap

Logstash version : 5.1.2
Java : jre 1.8.0_102
OS : windows

Any ideas?


Painless script error adding nested items
(system) #2

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