弹性搜索结合聚合
Elastic search combine aggregations
目前下面的查询删除了单个字段上的重复项 - "name",但我们需要所有字段的 top_hits 个结果:"name"、"venueName"、"venueTown".这是否可以在一个查询中实现而不发送 3 个请求并将 "field" 设置为 "venueName" 和 "venueTown"?
{
"aggs": {
"query": {
"terms": {
"field": "name"
}
,
"aggs": {
"top": {
"top_hits": {
"size": 1
}
}
}
}
},
"size": 0,
"query": {
"multi_match": {
"query": "LAURA",
"operator": "OR",
"fields": [
"name",
"venueName",
"venueTown"
]
}
}
}
如果我没理解错的话,你可以编写多个具有热门点击的聚合。
{
"query": {
"multi_match": {
"query": "LAURA",
"fields": [
"name",
"venueName",
"venueTown",
]
}
},
"aggs": {
"name": {
"terms": {
"field": "name"
},
"aggs": {
"top": {
"top_hits": {
"size": 1
}
}
}
},
"venue_name": {
"terms": {
"field": "venueName"
},
"aggs": {
"top": {
"top_hits": {
"size": 1
}
}
}
},
"venue_town": {
"terms": {
"field": "venueTown"
},
"aggs": {
"top": {
"top_hits": {
"size": 1
}
}
}
}
}
}
目前下面的查询删除了单个字段上的重复项 - "name",但我们需要所有字段的 top_hits 个结果:"name"、"venueName"、"venueTown".这是否可以在一个查询中实现而不发送 3 个请求并将 "field" 设置为 "venueName" 和 "venueTown"?
{
"aggs": {
"query": {
"terms": {
"field": "name"
}
,
"aggs": {
"top": {
"top_hits": {
"size": 1
}
}
}
}
},
"size": 0,
"query": {
"multi_match": {
"query": "LAURA",
"operator": "OR",
"fields": [
"name",
"venueName",
"venueTown"
]
}
}
}
如果我没理解错的话,你可以编写多个具有热门点击的聚合。
{
"query": {
"multi_match": {
"query": "LAURA",
"fields": [
"name",
"venueName",
"venueTown",
]
}
},
"aggs": {
"name": {
"terms": {
"field": "name"
},
"aggs": {
"top": {
"top_hits": {
"size": 1
}
}
}
},
"venue_name": {
"terms": {
"field": "venueName"
},
"aggs": {
"top": {
"top_hits": {
"size": 1
}
}
}
},
"venue_town": {
"terms": {
"field": "venueTown"
},
"aggs": {
"top": {
"top_hits": {
"size": 1
}
}
}
}
}
}