【问题标题】:Remove an entry from array in elastic search在弹性搜索中从数组中删除一个条目
【发布时间】:2018-08-10 22:14:18
【问题描述】:

我必须从弹性搜索中的哈希数组中删除一个哈希。我尝试了以下查询,但没有一个有效。请帮忙。

网址:发布https://127.0.0.1:9292/group/98902/_update

{
script : "for (int i = 0; i < ctx._source.users.size(); i++) 
{if(ctx._source.users[i].id == id){ctx._source.users.remove(i);}}",
"params" : {
    "id" : "9890"
}
}

{script: "ctx._source.users.remove(user)",
"params" : {
    "user": 
        {
        id: "9890"
    }
}}

我没有得到回应。

{ "error": "ElasticsearchIllegalArgumentException[未能执行脚本];嵌套:ScriptException[禁用 [groovy] 的动态脚本];", “状态”:400 }

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    https://github.com/elastic/elasticsearch/issues/21375

    这是我找到的必须为您服务的解决方案。

    它对我有用,所以试试看

    ctx._source.field.remove(ctx._source.field.indexOf(params.value))
    

    【讨论】:

      【解决方案2】:

      从 ES 1.5 开始,“动态脚本”(从请求中执行非沙盒脚本)默认被禁用。

      不推荐,但您可以选择使用此配置:

      script.inline: true
      script.indexed: true
      

      https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html

      【讨论】:

      • 谢谢杰瑞米。实际上,我才知道,我无权更新配置。所以,我必须得到文件并更新它。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-14
      • 2017-09-25
      • 1970-01-01
      • 2020-10-21
      • 1970-01-01
      • 1970-01-01
      • 2014-07-03
      相关资源
      最近更新 更多