我的情况是,我对 ElasticSearch 结果应用了限制,但它对我不起作用。我已经阅读了 下面的ES 指南 是我的代码:
module Invoices
class RestaurantBuilder < Base
def query(options = {})
buckets = {}
aggregations = {
orders_count: { sum: { field: :orders_count } },
orders_tip: { sum: { field: :orders_tip } },
orders_tax: { sum: { field: :orders_tax } },
monthly_fee: { sum: { field: :monthly_fee } },
gateway_fee: { sum: { field: :gateway_fee } },
service_fee: { sum: { field: :service_fee } },
total_due: { sum: { field: :total_due } },
total: { sum: { field: :total } }
}
buckets_for_restaurant_invoices buckets, aggregations, options[:restaurant_id]
filters = []
filters << time_filter(options)
query = {
query: { bool: { filter: filters } },
aggregations: buckets,
from: 0,
size: 5
}
query
end
def buckets_for_restaurant_invoices(buckets, aggregations, restaurant_id)
restaurant_ids(restaurant_id).each do |id|
buckets[id] = {
filter: { term: { restaurant_id: id } },
aggregations: aggregations
}
end
end
def restaurant_ids(restaurant_id)
if restaurant_id
[restaurant_id]
else
::Restaurant.all.pluck :id
end
end
end
end
restaurant_ids 函数返回大约 5.5k 家餐厅,所以在这种情况下,我收到错误“circuit_breaking_exception”,“reason”:“[request] 数据太大,[] 的数据将是 [622777920/593.9mb],大于[622775500/593.9mb]"的限制。这就是为什么我想应用一些限制,这样我一次只能获得几百条记录。
谁能指导我哪里做错了?