2017-07-28 107 views
1

我有一個問題,我想搜索結果使用建議。 我喜歡的類型是這樣es查詢在elasticsearch中的建議5.0.1

` 
{ 
    "name": { 
     "input": [ 
      "uers1" 
     ] 
    }, 
    "usertype": 1 
}{ 
    "name": { 
     "input": [ 
      "uers2" 
     ] 
    }, 
    "usertype": 2 
}` 

模式我想搜索數據的建議,這樣的

`{ 
    "suggest": { 
     "person_suggest": { 
      "text": "us", 
      "completion": { 
       "field": "name" 
      } 
     } 
    } 
}` 

查詢而像這些

`{ 
    "_shards": { 
     "total": 1, 
     "successful": 1, 
     "failed": 0 
    }, 
    "person_suggest": [ 
     { 
      "text": "word", 
      "offset": 0, 
      "length": 4, 
      "options": [ 
       { 
        "name": "user1", 
        "usertype": 1, 
        "score": 1 
       }, 
       { 
        "text": "user2", 
        "usertype": 2, 
        "score": 1 
       } 
      ] 
     } 
    ] 
} ` 

的結果,但我只想要結果usertype = 1,就像在mysql中添加where條件一樣。任何機構都可以幫助我?我想要一個DSL查詢。很多。

回答

0

你不能過濾完成建議查詢。針對您的問題的解決方案,爲每個usertype製作不同的完成字段或使用nGram分析器使用標準查詢。

+0

確定thx非常多 – littletwolee