【问题标题】:ElasticSearch show data according to restaurant_id and its average timeElasticSearch 根据 restaurant_id 及其平均时间显示数据
【发布时间】:2018-10-18 09:45:36
【问题描述】:

我是ElasticSearch的新手,想知道是否可以根据restaurant_id显示数据,然后是确认订单的平均时间。例如,我有文件:

{ _index: "orders-development",
_type: "order",
_id: "4412917",
_score: 1,
_source: {confirm_duration: 5}
}

{ _index: "orders-development",
_type: "order",
_id: "4412917",
_score: 1,
_source: {confirm_duration: 4}
}

{ _index: "orders-development",
_type: "order",
_id: "4322923",
_score: 1,
_source: { confirm_duration: 12}
}

以上是存储在ES中的文件,现在我要根据restaurant_id显示数据,然后是平均时间。所以现在我使用下面的代码并显示错误 "reason":"[terms] unknown field [avg], parser not found"

aggregations = {
  avg_order_confirmation: {
    terms: {
      field: :restaurant_id,
      size: 100,
      avg: { field: :confirm_duration },
    }
  }
}

【问题讨论】:

    标签: ruby-on-rails elasticsearch elasticsearch-rails elasticsearch-model


    【解决方案1】:

    您快到了,您需要将avg 移动到terms 的子聚合:

    aggregations = {
      avg_order_confirmation: {
        terms: {
          field: :restaurant_id,
          size: 100
        },
        aggs: {
          avg_confirmation: {
            avg: { field: :confirm_duration }
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-17
      • 2020-02-09
      • 2018-02-28
      • 1970-01-01
      • 2017-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-04
      相关资源
      最近更新 更多