how to remove arraylist value in elastic search using curl?

后端 未结 1 1823
悲哀的现实
悲哀的现实 2020-12-31 13:48

How to remove arraylist values in Elasticsearch using sense console or curl?

i want to remove any array element.?

POST /q/q/
{
    \"a\": [
    \"z\"         


        
相关标签:
1条回答
  • 2020-12-31 14:10

    If you want to remove all occurrences in the list, you can do this:

    {
      "script": {
        "lang": "painless",
        "inline": "ctx._source.a.removeAll(Collections.singleton('1'))"
      }
    }
    

    or if you want to remove just the first, like this:

    {
      "script": {
        "lang": "painless",
        "inline": "ctx._source.a.remove(ctx._source.a.indexOf('1'))"
      }
    }
    

    Also note that if you want to use double-quotes, it's fine, but you need to escape them, like ctx._source.a.indexOf(\"1\")).

    Or with params:

    {
      "script": {
        "lang": "painless",
        "inline": "ctx._source.a.remove(ctx._source.a.indexOf(yourParamName))",
        "params": {
          "yourParamName": "1"
        }
      }
    }
    
    0 讨论(0)
提交回复
热议问题