我正在使用彈性搜索 8.2
我有一個名為product_name(型別 - 文本,關鍵字)的欄位,其中包含產品名稱。
產品名稱有空格。例如:軌道鑰匙、XPress 開瓶器、InstaPress 咖啡機、Uno Comfort Wear 等。
我只想要 Orbital Keys 或 InstaPress 咖啡機的檔案。
我嘗試使用,terms(使用must是因為我還有其他條件要添加):
{
"query":{
"bool":{
"must":[
{
"terms":{
"product_name": ["Orbital Keys", "InstaPress Coffee Maker"]
}
}
]
}
}
}
這沒有回傳任何結果。
我試過了should,match_phrase它有效:
{
"query":{
"bool":{
"should":[
{
"match_phrase":{
"product_name": "Orbital Keys"
}
},
{
"match_phrase":{
"product_name": "InstaPress Coffee Maker"
}
}
]
}
}
}
是should在一個欄位中找到多個短語的最佳方法還是有其他方法可以解決這個問題?
感謝你的幫助
uj5u.com熱心網友回復:
您使用了Term 查詢,在這種情況下,您必須在查詢中使用關鍵字欄位,因為匹配是精確的。
我想您的映射如下所示:
{
"mappings": {
"properties": {
"product_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
您對條款的查詢應該是這樣的:
GET test/_search
{
"query":{
"bool":{
"must":[
{
"terms":{
"product_name.keyword": ["Orbital Keys", "InstaPress Coffee Maker"]
}
}
]
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/491190.html
標籤:弹性搜索
上一篇:Elasticsearch如何如此快速地通過文本進行查詢?
下一篇:彈性搜索不可用時的休眠搜索回退
