elasticsearch多个索引的多个大小选项



我的目标:为索引1返回15个结果,为其他索引返回10个结果

我的问题:自"hotel_name"是最重要的字段,它只存在于第一个索引中,根据查询,响应只包含来自index1

的数据。请求你李:"/index1、index2 index3/_search ?大小= 25">

{
"query": {
"multi_match": {
"query": "hotel",
"type": "phrase_prefix",
"fields": [
"hotel_name^9",
"country^8",
"city^7",
"destination^6",
"state^5",
"zone^4",
"title^3",
"description_short^2",
"description^1"
]
}
}
}

编辑:@llermaly answer:

Post request on: http://127.0.0.1:9200/_msearch

请求负载:

{"index":"index_1"}
{"size":30,"query":{"multi_match":{"query":"hotel","type":"phrase_prefix","fields":["hotel_name^8","country^7","city^6","destination^5","state^4","zone^3","description_short^2","description^1"]}}}
{"index":"index_2,index_2,index_3"}
{"size":10,"query":{"multi_match":{"query":"hotel","type":"phrase_prefix","fields":["country^8","city^7","destination^6","state^5","zone^4","title^3","description_short^2","description^1"]}}}

你不能在一个多索引_search查询中设置多个大小,但是你可以使用multi Search API为每个索引查询设置不同的大小。

GET _msearch
{"index": "index1"}
{
"size": 15
"query": {
"multi_match": {
"query": "hotel",
"type": "phrase_prefix",
"fields": [
"hotel_name^9",
"country^8",
"city^7",
"destination^6",
"state^5",
"zone^4",
"title^3",
"description_short^2",
"description^1"
]
}
}
}
{"index": "index2"}
{
"size": 10
"query": {
"multi_match": {
"query": "hotel",
"type": "phrase_prefix",
"fields": [
"country^8",
"city^7",
"destination^6",
"state^5",
"zone^4",
"title^3",
"description_short^2",
"description^1"
]
}
}
}
{"index": "index3"}
{
"size": 10
"query": {
"multi_match": {
"query": "hotel",
"type": "phrase_prefix",
"fields": [
"country^8",
"city^7",
"destination^6",
"state^5",
"zone^4",
"title^3",
"description_short^2",
"description^1"
]
}
}
}

可以使用查询模板来避免重复。

最新更新