Elasticsearch建议者过滤器按特定条件

时间:2019-07-09 09:57:21

标签: elasticsearch search-suggestion

我的查询如下

{
  "suggest": {
    "text": "iphame",
    "0-title": {
      "phrase": {
        "field": "title",
        "query": {
          "term": {
            "country_id": 123
          }
        }
      }
    },
    "1-subtitle": {
      "phrase": {
        "field": "subtitle"
      }
    }
  }
}

我想要基于国家/地区的搜索建议过滤器,但是上面的查询导致了parsing_exception

如何使查询仅基于特定国家/地区查找标题?

| id | title                   | subtitle    | country_id |
|----|-------------------------|-------------|------------|
| 1  | Cheapest iPhone in town | Lorem ipsum | 123        |
| 2  | iOS 13 beta released    | Lorem ipsum | 25         |
| 3  | iPadOS public beta      | Lorem ipsum | 123        |

例如我不想包含id = 2

1 个答案:

答案 0 :(得分:0)

如果您将country_id映射为数字,则:

{ 
"query": { 
    "match": { 
            "country_id": 123 
        } 
    }
} 

如果您将country_id映射为关键字,则:

{ 
"query": { 
    "match": { 
            "country_id.keyword": "123" 
        } 
    }
}