elasticsearch 对同一字段的2个值进行筛选
我有一个状态字段,它可以有以下值之一 我可以筛选状态为“已完成”的数据。我还可以看到正在进行的数据 但我想同时显示状态为“已完成”和“正在进行”的数据 但我不知道如何为单个字段上的2个值添加过滤器 我怎样才能实现我想要的 编辑-谢谢你的回答。但这不是我想要的 就像这里我已经过滤了
elasticsearch 对同一字段的2个值进行筛选,
elasticsearch,kibana,dashboard,
elasticsearch,Kibana,Dashboard,我有一个状态字段,它可以有以下值之一 我可以筛选状态为“已完成”的数据。我还可以看到正在进行的数据 但我想同时显示状态为“已完成”和“正在进行”的数据 但我不知道如何为单个字段上的2个值添加过滤器 我怎样才能实现我想要的 编辑-谢谢你的回答。但这不是我想要的 就像这里我已经过滤了状态:completed,我想用这种精确的方式过滤2个值 我知道我可以编辑这个过滤器,并使用您的查询,但我需要一个简单的方法来做到这一点(查询方式很复杂),因为我必须向我的营销团队展示它,他们对查询没有任何概念。我需
状态:completed
,我想用这种精确的方式过滤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"
}
}
}
}
如果我正确理解了您的问题,您希望对字段的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中的引用查询,应该类似于或
条件
{
"query":{
"bool":{
"should":[
{"must":{"status":"completed"}},
{"must":{"status":"ongoing"}}
]
}
},
"aggs" : {
"booking_status" : {
"terms" : {
"field" : "status"
}
}
}
}
对于elasticsearch中的引用查询,应该类似于或
条件
{
"query":{
"bool":{
"should":[
{"must":{"status":"completed"}},
{"must":{"status":"ongoing"}}
]
}
},
"aggs" : {
"booking_status" : {
"terms" : {
"field" : "status"
}
}
}
}
在聚合中需要一个过滤器
{
"size": 0,
"aggs": {
"agg_name": {
"filter": {
"bool": {
"should": [
{
"terms": {
"status": [
"completed",
"ongoing"
]
}
}
]
}
}
}
}
}
使用上述查询可获得如下结果:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 8,
"max_score": 0,
"hits": []
},
"aggregations": {
"agg_name": {
"doc_count": 6
}
}
}
您想要的结果是文档计数您需要在聚合中使用过滤器
{
"size": 0,
"aggs": {
"agg_name": {
"filter": {
"bool": {
"should": [
{
"terms": {
"status": [
"completed",
"ongoing"
]
}
}
]
}
}
}
}
}
使用上述查询可获得如下结果:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 8,
"max_score": 0,
"hits": []
},
"aggregations": {
"agg_name": {
"doc_count": 6
}
}
}
您想要的结果是doc\u count
您尝试过这个查询吗?或者,在尝试此查询时,是否可以对SQL查询ID进行注释?或者您可以对SQL查询进行注释吗