【问题标题】:scripted_metric aggregation: map_script and combine_script not invokedscripted_metric 聚合:未调用 map_script 和 combine_script
【发布时间】:2015-08-04 21:53:30
【问题描述】:

我刚刚开始使用 ElasticSearch (v1.5) scripted_metric 聚合,并且在尝试 example aggregation from the documentation 时已经绊倒了。

在我发现如何从脚本中access the elasticsearch logger 之后,结果发现只有init_scriptreduce_script 被调用,而map_scriptcombine_script 被省略了,即使在将脚本减少到仅仅是记录。

[...]
  "aggs": {
    "test": {
      "scripted_metric": {
            "init_script" : "import  org.elasticsearch.common.logging.*; ESLogger logger=ESLoggerFactory.getLogger('myscript');logger.error('1')",
            "map_script" : "import  org.elasticsearch.common.logging.*; ESLogger logger=ESLoggerFactory.getLogger('myscript');logger.error('2')", 
            "combine_script" : "import  org.elasticsearch.common.logging.*; ESLogger logger=ESLoggerFactory.getLogger('myscript');logger.error('3')",
            "reduce_script" : "import  org.elasticsearch.common.logging.*; ESLogger logger=ESLoggerFactory.getLogger('myscript');logger.error('4')"
      }
    }
  }
[...]

日志

[2015-08-04 08:31:31,841][ERROR][myscript                 ] 1
[2015-08-04 08:31:31,841][ERROR][myscript                 ] 1
[2015-08-04 08:31:31,843][ERROR][myscript                 ] 1
[2015-08-04 08:31:31,844][ERROR][myscript                 ] 1
[2015-08-04 08:31:31,845][ERROR][myscript                 ] 1
[2015-08-04 08:31:32,020][ERROR][myscript                 ] 4

之前,我从文档示例的略微修改版本开始:

[...]
  "aggs": {
    "test": {
      "scripted_metric": {
         "init_script" : "_agg['transactions'] = []",
            "map_script" : "_agg.transactions.add(2)", 
            "combine_script" : "profit = 0; for (t in _agg.transactions) { profit += t }; return profit",
            "reduce_script" : "profit = 0; for (a in _aggs) { profit += a }; return profit"
      }
    }
  }
[...]

由于

导致 ReduceSearchPhaseException 失败
[Ambiguous method overloading for method java.lang.Integer#plus.
Cannot resolve which method to invoke for [null] due to overlapping prototypes between:
    [class java.lang.Character]
    [class java.lang.String]
    [class java.lang.Number]]

发生这种情况是因为在reduce_script_aggs 数组由五个nulls 组成,如果map_scriptcombine_script 不运行,这完全有意义。

但是他们为什么不跑呢?任何深入挖掘的想法都值得赞赏。

【问题讨论】:

    标签: elasticsearch aggregation


    【解决方案1】:

    如果应用了过于严格的过滤器以致找不到文档,则会发生这种情况。就我而言,bool 过滤器隐藏在我的邮递员的折叠上方,我花了一些时间才意识到 - 抱歉,多么愚蠢的错误:-/

    显然,在空的搜索结果中,mapcombine 没有任何内容。

    【讨论】:

      猜你喜欢
      • 2022-01-15
      • 2019-07-20
      • 2014-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多