gpt4 book ai didi

elasticsearch - 过滤相同字段的2个值

转载 作者:行者123 更新时间:2023-12-03 00:55:06 25 4
gpt4 key购买 nike

我有一个状态字段,可以包含以下值之一,

enter image description here
我可以过滤状态已完成的数据。我还可以看到正在进行的数据。

但是我想同时显示状态为已完成和正在进行的的数据。

但是我不知道如何在单个字段上为2个值添加过滤器。

我怎样才能实现自己想要的?

编辑-感谢您的答案。但这不是我想要的。

enter image description here

就像这里我已经过滤了status:completed一样,我想以这种确切的方式过滤2个值。

我知道我可以编辑此过滤器和,并使用您的查询,但是我需要一种简单的方法(查询方式很复杂),因为我必须向我的营销团队展示它,而他们对查询一无所知。我需要说服他们。

最佳答案

如果我正确理解了您的问题,则希望对一个字段的2个值进行汇总。

这可以通过类似于术语查询的查询来实现:

{
"size" : 0,
"query" : {
"bool" : {
"must" : [ {
"terms" : {
"status" : [ "completed", "unpaid" ]
}
} ]
}
},
"aggs" : {
"freqs" : {
"terms" : {
"field" : "status"
}
}
}
}

这样会得到如下结果:
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 3,
"successful" : 3,
"failed" : 0
},
"hits" : {
"total" : 5,
"max_score" : 0.0,
"hits" : [ ]
},
"aggregations" : {
"freqs" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [ {
"key" : "unpaid",
"doc_count" : 4
}, {
"key" : "completed",
"doc_count" : 1
} ]
}
}
}

这是我的玩具映射定义:
{
"bookings" : {
"properties" : {
"status" : {
"type" : "keyword"
}
}
}
}

关于elasticsearch - 过滤相同字段的2个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45757192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com