how to remove arraylist value in elastic search using curl?

我怕爱的太早我们不能终老 提交于 2019-12-19 00:40:09

问题


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

i want to remove any array element.?

POST /q/q/
{
    "a": [
    "z", "q", "1"
    ]
}

it doesnt work for me:

POST /q/q/AV4sjk40mWHLgYFNkmNd/_update
{
    "script": {
        "lang": "painless",
        "inline": "ctx._source.a -=newsupp",
        "params": {
            "newsupp": "p" 
        }
     }
}

or

POST /q/q/AV4sjk40mWHLgYFNkmNd/_update
{
    "script": {
        "lang": "painless",
        "inline": "ctx._source.a.remove("1")"
    }
}

回答1:


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"
    }
  }
}


来源:https://stackoverflow.com/questions/45980054/how-to-remove-arraylist-value-in-elastic-search-using-curl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!