我正在使用彈性搜索查詢一個欄位。該欄位可以是“小”、“中”、“平均”、“大”。
但我希望“小”和“中”回傳“是”,“平均”和“大”回傳“否”
有沒有辦法在查詢中做到這一點?或者在反應式搜索中使用串列組件?
謝謝
uj5u.com熱心網友回復:
您可以使用script_field
{
"_source": "*",
"script_fields": {
"custom_field": {
"script": {
"source": """
if(doc['description.keyword'].value=='Small' || doc['description.keyword'].value=='Medium')
return 'Yes';
else
return 'No';
"""
}
}
}
}
結果
"hits" : [
{
"_index" : "index68",
"_type" : "_doc",
"_id" : "GyEhPYQBJutE-yZceoEO",
"_score" : 1.0,
"_source" : {
"description" : "Small",
"title" : "A"
},
"fields" : {
"custom_field" : [
"Yes"
]
}
},
{
"_index" : "index68",
"_type" : "_doc",
"_id" : "HCEhPYQBJutE-yZcpoGE",
"_score" : 1.0,
"_source" : {
"description" : "Medium",
"title" : "B"
},
"fields" : {
"custom_field" : [
"Yes"
]
}
},
{
"_index" : "index68",
"_type" : "_doc",
"_id" : "HSEhPYQBJutE-yZctoHu",
"_score" : 1.0,
"_source" : {
"description" : "Average",
"title" : "B"
},
"fields" : {
"custom_field" : [
"No"
]
}
},
{
"_index" : "index68",
"_type" : "_doc",
"_id" : "HiEhPYQBJutE-yZc04Fx",
"_score" : 1.0,
"_source" : {
"description" : "Big",
"title" : "C"
},
"fields" : {
"custom_field" : [
"No"
]
}
}
]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/526561.html
標籤:弹性搜索反应式搜索
下一篇:org.springframework.beans.factory.BeanCreationException:創建類路徑資源中定義的名稱為“OpensearchClient”的bean時出錯
