1

Imagine the following document into my index:

PUT test

POST test/_doc/1
{
  "name": "old_name",
  "data": {
    "foo": "bar",
    "lol": "alright"
  },
  "collections": ["first", "second"]
}

I would like to transform my document to:

{
    "name" : "new_name",
    "data": {
      "foo": "lol"
    },
    "collections": ["first", "second"]
}

Problem is, if I use the update API like the following:

POST test/_doc/1/_update
{
    "doc" : {
        "name" : "new_name",
        "data": {
          "foo": "lol"
        }
    }
}

The document becomes

{
  "name": "new_name",
  "data": {
    "foo": "lol",
    "lol": "alright"
  },
  "collections": [
    "first",
    "second"
  ]
}

And the "lol" attribute have not been removed.

I only want my request to remove all attributes nested in the data key to be removed if not present in the update request, but I want other attributes to stay (like the collections key).

I know that the ElasticSearch documentation says:

The update API also supports passing a partial document, which will be merged into the existing document (simple recursive merge, inner merging of objects, replacing core "keys/values" and arrays)

Is their something easy I could do to respond to my problem, should I make multiple requests?

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.