Elastic Search update api - updating complex data including array objects and parts of document

I have complex structure of data coming in as bellow:

{
    ​​​​​
    "id": 1,
    "other_details": [{
            ​​​​​
            "address_details": {
                ​​​​​
                "city": "pune",
                "country": "India",
                "state": "Maharashtra"
            }
            ​​​​​,
            "profession_details": [{
                    ​​​​​
                    "pfid": 1,
                    "post": "Trainee",
                    "start": "2010",
                    "end": "2011"
                }
                ​​​​​, {
                    ​​​​​
                    "pfid": 2,
                    "post": "Software Engineer",
                    "start": "2011",
                    "end": "2014"
                }
                ​​​​​
            ],
            "education": "BE"
        }
        ​​​​​
    ],
    "created": "2010",
    ....(some other fields)
}
​​​​```

Here..
I have an use case to update the elements of an array.
Below are the 3 different update events for the same id["id":1]

1) json 1
{
    ​​​​​
    "id": "1",
    "other_details": [{
            ​​​​​
            "address_details": {
                ​​​​​
                "city": "Pune",
                "country": "India",
                "state": "Maharashtra"
            }
            ​​​​​
        }
        ​​​​​
    ],
    "created": "2012"
}
​​​​​
2) json 2
{
    ​​​​​
    "id": "1",
    "other_details": [{
            ​​​​​
            "profession_details": [{
                    ​​​​​
                    "pfid": 1,
                    "post": "Trainee",
                    "start": "2010"
                }
                ​​​​​
            ],
            "education": "BE"
        }
        ​​​​​
    ]
}
​​​​​
3) json 3
{
    ​​​​​
    "id": "1",
    "other_details": [{
            ​​​​​
            "profession_details": [{
                    ​​​​​
                    "pfid": 2,
                    "post": "Software Engineer",
                    "start": "2011",
                    "end": "2014"
                }
                ​​​​​, {
                    ​​​​​
                    "pfid": 1,
                    "end": "2011"
                }
                ​​​​​
            ]
        }
        ​​​​​
    ]
}


The output which we are expecting is as below -

{
    ​​​​​
    "id": "1",
    "other_details": [{
            ​​​​​
            "address_details": {
                ​​​​​
                "city": "Pune",
                "country": "India",
                "state": "Maharashtra"
            }
            ​​​​​,
            "profession_details": [{
                    ​​​​​
                    "pfid": 1,
                    "post": "Trainee",
                    "start": "2010",
                    "end": "2011"
                }
                ​​​​​, {
                    ​​​​​
                    "pfid": 2,
                    "post": "Software Engineer",
                    "start": "2011",
                    "end": "2014"
                }
                ​​​​​
            ],
            "education": "BE"
        }
        ​​​​​
    ],
    "created": "2012"
}
​​​​
Basically whenever there is an update in the array elements(professional_details - in this example), that has to be updated in the source document.

Kindly help me out !
​

If i understand your question correcttly you want to update array inside the existing document.

There are 2 option:

  1. you can send entire new json/document (with updated array) to index and it will replace exsiting document.
  2. you can use script with upsert to updating document. Please check official document for upsert with script.

Below are some other link which will help you to resolved this:

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