带有过滤器的Elasticsearch simple_query_string

时间:2017-04-30 18:06:16

标签: elasticsearch querydsl

我有以下查询查询(simple_query_string)并且也建议,但在它执行任何此操作之前,我想使用术语过滤数据。

{
    "query": {
      "simple_query_string": {
        "fields": ["merchant.basic"],
        "query": "(sterbuck|sterbuck*)",
        "default_operator": "and"
      }
    },
    "suggest": {
      "text": "sterbuck",
      "phraseSuggestion": {
        "phrase": {
          "field": "merchant.basic",
          "direct_generator": [{
            "field": "merchant.basic",
            "suggest_mode": "popular",
            "min_word_length": 3,
            "prefix_length": 2
          }]
        }
      }
    },
    "size": 4,
    "_source": ["merchant"]
  }

提前谢谢。

1 个答案:

答案 0 :(得分:2)

{
   "query":{
      "bool":{
         "must":{
             "simple_query_string": {
            "fields": ["merchant.basic"],
            "query": "(star|star*)",
            "default_operator": "and"
          }
         },
         "filter":{
            "term":{
               "name":"michael"
            }
         }
      }
   },
   "suggest": {
       "text": "sterbuck",
          "phraseSuggestion": {
            "phrase": {
              "field": "merchant.basic",
              "direct_generator": [{
                "field": "merchant.basic",
                "suggest_mode": "popular",
                "min_word_length": 3,
                "prefix_length": 2
              }]
            }
          }
    },
    "size": 4,
    "_source": ["merchant"]
}