1

Recently, I posted the following about adding a string to existing (inconsistent) arrays in documents: ElasticSearch query to populate or append a value to a field

The marked solution is working perfectly.

But now I need to understand how to delete one of the 5-character codes from the arrays. Assuming I now need to delete the code 'ABCDE' from the documents, while leaving the other codes in the array untouched, what would that query look like?

1 Answer 1

1

In below script I am looping through array and creating a list by removing the given value.

Please test before running on actual data.

{
  "script": {
    "source": "ctx._source.customCategories.removeAll(Collections.singleton(params.catg))",
    "lang": "painless",
    "params": {
      "catg": "c"
    }
  }
}
Sign up to request clarification or add additional context in comments.

15 Comments

Hi Jaspreet. Good to see you again. I will try this after my morning meeting. In the meantime, can you suggest some online documentation or video tutorial for me to learn the painless language and syntax for ES?
Hi Jaspreet. I've run your query on some test sources. The query does remove the custom category value as intended, but, it's doing that thing again where the fields are displayed out of order for any documents which I've run the query against. You were able to somehow address this in the other post. Can you please advise?
Just FYI, sample document and mapping are identical to the other thread. Thanks.
I have updated the answer. I think this should work fine
|

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.