【问题标题】:Unable to give condition to watcher for elasticsearch?无法为弹性搜索的观察者提供条件?
【发布时间】:2015-06-26 13:35:25
【问题描述】:

我安装了观察者并给出了条件。在给出条件时,它给了我一个错误......

{"error":"WatcherException[failed to put watch [log_error_watch]]; nested:ScriptConditionValidationException[failed to compile script [returnctx.payload.hits.total > 5] with lang [groovy] of type [INLINE]]; nested:ScriptException[dynamic scripting for [groovy] disabled]; ","status":500}

什么是动态脚本?它给我的错误是它被禁用了。 我对观察者的条件如下。

curl -XPUT 'http://localhost:9200/_watcher/watch/log_error_watch' -d '{
  "metadata" : { 
    "color" : "red"
  },
  "trigger" : { 
    "schedule" : {
      "interval" : "10s"
    }
  },
  "input" : { 
    "search" : {
      "request" : {
        "search_type" : "count",
        "indices" : "logs",
        "body" : {
          "query" : { "match" : { "status" : "error" } }
        }
      }
    }
  },
  "condition" : { 
    "script" : "return ctx.payload.hits.total > 5"
  },
  "transform" : { 
    "search" : {
        "request" : {
          "indices" : "logs",
          "body" : {
            "query" : { "match" : { "status" : "error" } }
          }
        }
    }
  },
  "actions" : { 
    "my_webhook" : {
      "webhook" : {
        "method" : "GET",
        "host" : "mylisteninghost",
        "port" : 9200,
        "path" : "/{{watch_id}}",
        "body" : "Encountered {{ctx.payload.hits.total}} errors"
      }
    },
    "email_administrator" : {
      "email" : {
        "to" : "xxxxxx.xxx@gmail.com",
        "subject" : "Encountered {{ctx.payload.hits.total}} errors",
        "body" : "Too many error in the system, see attached data",
        "attach_data" : true,
        "priority" : "high"
      }
    }
  }
}'

【问题讨论】:

    标签: groovy elasticsearch scripting mailing elasticsearch-watcher


    【解决方案1】:

    @andrei 关于如何在 Elasticsearch 中启用动态脚本是正确的,我正要粘贴相同的链接。

    但是,根据您指定的条件,您似乎根本不需要使用脚本! Watcher 有一个compare 条件,看起来非常合适:

    https://www.elastic.co/guide/en/watcher/current/condition.html#condition-compare

    在您的情况下,条件如下所示:

        {
      ...
    
      "condition" : {
        "compare" : {
          "ctx.payload.hits.total" : { 
            "gte" : 5 
          }
      }
      ...
    }
    

    【讨论】:

    • 我删除了观察者历史并重新安装。我又遇到这样的错误了…… -------------------------------------------------- ---> {"error":"WatcherException[failed to put watch [error_status]];嵌套:StrictDynamicMappingException[映射设置为严格,[watch]内不允许动态引入[_status]]; ","status" :500}
    • 您好像安装了预发布版本的 watcher。请按照此处的说明进行升级:elastic.co/guide/en/watcher/current/…
    【解决方案2】:

    您需要在 Elasticsearch 中启用动态脚本:https://www.elastic.co/guide/en/watcher/current/condition.html#condition-script

    评估脚本的监视条件。默认的脚本语言是 groovy。您可以使用 Elasticsearch 支持的任何脚本语言,只要该语言支持将表达式计算为布尔值即可。请注意,小胡子和表达式语言过于受限,无法在此条件下使用。有关更多信息,请参阅 Elasticsearch 参考中的脚本。

    重要

    您必须在 elasticsearch.yml 中显式启用动态脚本才能使用内联或索引脚本。

    实际上启用动态脚本:https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#enable-dynamic-scripting

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-30
      相关资源
      最近更新 更多