2015-06-30 82 views
0

任何人都知道如何從建議的結果集中過濾拼寫錯誤?Elasticsearch修剪建議

此查詢找到很好的建議,但也包括部分拼寫錯誤。例如「商業摩根」返回「商業抵押」,這是好的,但也是「商業抵押貸款」,這是不好的,因爲商業術語仍然是錯誤的。

{ 
    "suggest" : { 
    "text" : "comercial morgage", 
    "simple_phrase" : { 
     "phrase" : { 
     "analyzer" : "standard", 
     "field" : "title.raw", 
     "max_errors" : 0.8, 
     "size" : 3, 
     "highlight": { 
      "pre_tag": "<em>", 
      "post_tag": "</em>" 
     }, 
     "collate": { 
      "query": { 
      "match": { 
       "title.raw" : "{{suggestion}}" 
      } 
      }, 
      "prune": true 
     } 
     } 
    } 
    } 
} 

這將返回

{ 
    "took": 42, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { ... }, 
    "suggest": { 
    "simple_phrase": [ 
     { 
     "text": "comercial morgage", 
     "offset": 0, 
     "length": 17, 
     "options": [ 
      { 
      "text": "commercial mortgage", 
      "highlighted": "<em>commercial mortgage</em>", 
      "score": 0.0025874644, 
      "collate_match": true 
      }, 
      { 
      "text": "commercial mortgages", 
      "highlighted": "<em>commercial mortgages</em>", 
      "score": 0.0022214006, 
      "collate_match": true 
      }, 
      { 
      "text": "comercial mortgage", 
      "highlighted": "comercial <em>mortgage</em>", 
      "score": 0.0019709675, 
      "collate_match": true 
      } 
     ] 
     } 
    ] 
    } 
} 

的collat​​e_match 「COMERCIAL [EM]按揭[/ EM]」 是真實的,即使準確的詞組不會出現在任何文檔標題。

得分很低,非常相似,所以我不能過濾得分。

目前它在最後一頁看起來沒問題,因爲我用一個小小的javascript來顯示只有[em /]標記包圍的結果,但這是一個黑客,並不是很好。

elasticsearch的版本是1.5.3,但我們可能很快就會升級,因此我無法在建議中使用過濾器。

有誰知道如何過濾/修剪任何不存在於title.raw字段中的建議嗎?

謝謝。

回答

0

在分類查詢中,您可以使用任何您想要的查詢。

嘗試爲您的查詢添加默認運算符,因此您希望所有術語在該字段中匹配。

{ "suggest" : { "text" : "comercial morgage", "simple_phrase" : { "phrase" : { "analyzer" : "standard", "field" : "title.raw", "max_errors" : 0.8, "size" : 3, "highlight": { "pre_tag": "<em>", "post_tag": "</em>" }, "collate": { "query": { "match": { "title.raw" : { "query": "{{suggestion}}", "operator" : "and" } } }, "prune": true } } } } }