我有一個彈性搜索索引,其中包含我要對其執行通配符查詢的某個欄位。問題是該欄位在許多檔案中重復,因此我想首先使用聚合來獲取該欄位的唯一值,然后在此之上執行通配符查詢。有沒有辦法可以在彈性搜索中對聚合結果執行查詢?
uj5u.com熱心網友回復:
我相信您可以通過折疊搜索結果而不是使用首先獲取聚合結果然后運行通配符查詢的策略來找到所需的結果。
添加帶有索引資料(使用默認映射)、搜索查詢和搜索結果的作業示例。
指數資料:
{
"role": "example123",
"number": 1
}
{
"role": "example",
"number": 2
}
{
"role": "example",
"number": 3
}
搜索查詢:
{
"query": {
"wildcard": {
"role": "example*"
}
},
"collapse": {
"field": "role.keyword"
}
}
搜索結果:
"hits": [
{
"_index": "72724517",
"_id": "1",
"_score": 1.0,
"_source": {
"role": "example",
"number": 1
},
"fields": {
"role.keyword": [
"example"
]
}
},
{
"_index": "72724517",
"_id": "3",
"_score": 1.0,
"_source": {
"role": "example123",
"number": 1
},
"fields": {
"role.keyword": [
"example123"
]
}
}
]
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/495381.html
標籤:弹性搜索
