On Thu, Oct 29, 2020 at 05:11:51PM +0800, Lu Weitao wrote:
On Thu, Oct 29, 2020 at 02:23:55PM +0800, Zhang Yuhang wrote:
[why] Some queries need to limit the range of fields.
Signed-off-by: Zhang Yuhang zhangyuhang25@huawei.com
lib/es_query.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/lib/es_query.rb b/lib/es_query.rb index aaaadc2..037213d 100644 --- a/lib/es_query.rb +++ b/lib/es_query.rb @@ -36,12 +36,27 @@ class ESQuery end end
+# Range Query Example: +# range = { +# start_time: { +# gte: '2020-09-10 01:50:00', +# lte: '2020-09-10 01:53:00' +# },
这样也OK
如果用户给的给的是2020-09-10,2020-09-11 我们需要自动补全为'2020-09-10 00:00:00', '2020-09-11 23:59:59' 吗?
如果需要补全是在这里补全,还是在调用之前补全? 哪个好点?
Thanks, Weitao
我感觉应该在调用之前补全吧. 如果查询的字段,存在数据库中的格式是"yyyy-MM-dd", 再做补全就画蛇添足了.
Thanks, Zhang Yuhang
+# end_time: { +# gt: '2020-09-10 01:52:00', +# lt: '2020-09-10 01:54:00' +# } +# } +# items['range'] = range +# build_mutli_field_subquery_body(items) def build_mutli_field_subquery_body(items) query_fields = [] items.each do |key, value| if value.is_a?(Array) inner_query = build_multi_field_or_query_body(key, value) query_fields.push({ bool: { should: inner_query } })
- elsif key.to_s == 'range'
else query_fields.push({ term: { key => value } }) endquery_fields.concat(value.map { |k, v| { range: { k => v } } })
-- 2.23.0