我的弹性文件如下
我想要满足条件的搜索查询: 如何获得具有AREA = Mumbai和AREA = Chennai的那些OPERATIONS和CATEGORY值
因此输出应该是类别:咨询1,运营:监管运营
答案 0 :(得分:1)
使用terms Query
:
{
"query": {
"terms": {
"AREA": [
"Mumbai",
"Chennai"
]
}
}
}
答案 1 :(得分:1)
可能有用:
items
答案 2 :(得分:1)
试试这个让我知道:
{
"size": 0,
"query": {
"bool": {
"should": [
{
"term": {
"AREA": "mumbai"
}
},
{
"term": {
"AREA": "chennai"
}
}
]
}
},
"aggs": {
"unique_operations": {
"terms": {
"field": "OPERATIONS",
"size": 10
},
"aggs": {
"count_areas": {
"cardinality": {
"field": "AREA"
}
},
"top": {
"top_hits": {
"size": 2,
"_source": {
"include": ["CATEGORY"]
}
}
},
"areas_bucket_filter": {
"bucket_selector": {
"buckets_path": {
"areasCount": "count_areas"
},
"script": "areasCount == 2"
}
}
}
}
}
}
LATER EDIT :添加top_hits
聚合以获取涵盖类别请求的示例文档。
答案 3 :(得分:0)
请试试这个。
{
"query": {
"bool": {
"should": [
{
"query_string": {
"default_field": "AREA",
"query": "mumbai"
}
},
{
"query_string": {
"default_field": "AREA",
"query": "chennai"
}
}
]
}
}
}[![result][1]][1]