按子项聚合对Elasticsearch术语聚合进行排序

时间:2017-07-29 23:07:17

标签: elasticsearch elasticsearch-aggregation

我维护了一个大型Web应用程序,用户可以对图像进行投票。

为了帮助对抗用户的欺诈性投票,我在Elasticsearch中加载了一些投票数据,并通过投票方向,图像ID,用户ID和IP进行索引。我希望能够按IP汇总投票,然后按图像汇总(在这种情况下发布),然后按用户ID的基数汇总投票。

我希望在同一IP下投票的用户数量最多的图片能够成为最顶层字词聚合的顶部。不幸的是,尝试按父最大值对父项聚合进行排序并不起作用。

:size: 0
:aggs:
  :ip_votes:
    :terms:
      :field: ip
      :order:
        images>users.value.max: desc # <- doesn't work
    :aggs:
      :images:
        :terms:
          :field: image_id
          :order:
            users.value: desc
        :aggs:
          :users:
            :cardinality:
              :field: user_id

运行此聚合会产生一般错误:

  

无效术语聚合顺序路径[images&gt; users.value.max]。术语桶只能在子聚合器路径上进行排序,该路径由路径中的零个或多个单桶聚合构成,最后一个桶或路径末端的度量聚合。子路径[images]指向非单桶聚合。

如果无法直接完成此操作,我该如何完成?

集合的映射:

vote_stats:
  mappings:
    vote_stat:
      dynamic: "false"
      _all:
        enabled: false
      properties:
        created_at:
          type: "date"
        downvotes:
          type: "integer"
        image_id:
          type: "integer"
        ip:
          type: "ip"
        tag_ids:
          type: "integer"
        time_offset:
          type: "date"
        upvotes:
          type: "integer"
        user_id:
          type: "integer"

0 个答案:

没有答案