Upsert into nested field

I'm trying to upsert (push) and object into a nested field.

We have data in xml that comes in like this:

<Person>
<id>1234</id>
<name>John Smith</name>
<age/>
<position/>
</Person>
<addressInfo>
<AddressID>3424</AddressID>
<PersonID>1234</PersonID>
<address>123 xyz street</address>
<city>Town A</city>
<StateProvince>State A</StateProvince>
<Country>Country A</Country>
<PostalCode>85739</PostalCode>
</addressInfo>
<addressInfo>
<AddressID>7567</AddressID>
<PersonID>1234</PersonID>
<Address>3456 abc street</address>
<Sity>Town B</city>
<StateProvince>State B</StateProvince>
<Country>Country B</Country>
<PostalCode>12345</PostalCode>
</addressInfo>

Expected Output:

{
  "name": John Smith,
  "age": 34,
  "position": Accounting,
  "addresses": [
   {
        "address": "123 xyz street",
        "city": "Town A",
        "stateProvince": "State A",
        "country": "Country A",
        "postalCode": "85739"
    }, 
    {
        "address": "3456 abc street",
        "city": "Town B",
        "state": "State B",
        "country": "Country B",
        "postalCode": "12345"
    }]
}


Ruby Script to create addresses object:

ruby {
        code => '
          event.set("addresses", [
            {
              "address" => event.get("[profile][addressinfo][Address]"), 
              "city" => event.get("[profile][addressinfo][City]"),
              "stateProvince" => event.get("[profile][addressinfo][StateProvince]"),
              "country" => event.get("[profile][addressinfo][country]"),
              "postalCode" => event.get("[profile][addressinfo][PostalCode]")
            }
          ]
          )
        '
      }

Logstash Output:

elasticsearch {
        hosts => ["localhost:9200"]
        action => "update"
        doc_as_upsert => true
        document_id => "%{id}"     
        index => "sentinel"
        script => 'ctx._source.addresses.add("%{addresses}")'
    }

Error:

  "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"object mapping for [addresses] tried to parse field [null] as object, but found a concrete value"}}}}

bump. still trying to figure this one out

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