假設我必須在 Elastic Search Index (ES 7.15) 中過濾汽車建構式,其中欄位car_maker映射到keyword,在汽車制造商字串名稱中具有有限的可能性:
{
"mappings": {
"properties": {
"car_maker": {
"type": "keyword"
}
}
}
}
GET /cars/_search
{
"query": {
"bool": {
"filter": [{
"term": {
"car_maker": "Honda"
}
}]
}
}
}
這與匹配的查詢一起可以正常作業。該filter不會參與如期望的得分計算。現在我想為該查詢過濾更多汽車制造商(假設是一個should查詢):
{
"query": {
"bool": {
"filter" : [
{"term" : { "car_maker" : "Honda"}},
{"term" : { "car_maker" : "Ferrari"}}
]
}
}
}
這是行不通的。ES查詢引擎會出現任何錯誤,但也會有任何結果。當然總是不可能性到多個過濾器應用到像不同的欄位car_maker和car_color,但如何做相反的:應用多個值(Honda,Ferrari等),以相同的過濾器欄位car_maker象在上面的例子中,沒有調節得分計算?
uj5u.com熱心網友回復:
您可能想嘗試以下過濾器查詢:
{
"query" : {
"bool" : {
"filter" : {
"terms" : {
"car_maker" : ["Honda", "Ferrari"]
}
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/335552.html
