如何使用curl在弹性搜索中删除arraylist值?

问题描述:

如何使用感知控制台或 curl 删除 Elasticsearch 中的数组列表值?

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

它对我不起作用:

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

POST /q/q/AV4sjk40mWHLgYFNkmNd/_update
{
    "script": {
        "lang": "painless",
        "inline": "ctx._source.a.remove("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'))"
  }
}

还要注意,如果你想使用双引号,也可以,但是你需要对它们进行转义,比如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\")).

或者使用参数:

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