如何使用curl在弹性搜索中删除arraylist值? [英] how to remove arraylist value in elastic search using curl?

查看:38
本文介绍了如何使用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"
    }
  }
}

这篇关于如何使用curl在弹性搜索中删除arraylist值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆