2017-05-15 32 views
0

我正在使用彈性搜索自動完成,並糾正拼寫錯誤。我有我的領域(自動完成)的映射。映射提交Elastic Search

**Mapping:** 

     "name": { 
       "type": "text", 
       "analyzer": "autocomplete" 
       } 

現在我要實現這個field.When我使用它給因爲現有映射我想錯了result.Thats短語建議者。

**POST XYZ/_search** 

    { 
     "suggest": { 
     "text": "ipone 16", 
     "simple_phrase": { 
      "phrase": { 
      "field": "name", 
      "highlight": { 
       "pre_tag": "<em>", 
       "post_tag": "</em>" 
      } 
      } 
     } 
     } 
    } 

    **Results:** 
     "options": [ 
       { 
       "text": "i ip ipo iphon iphone 1 16", 
       "highlighted": "i ip ipo <em>iphon iphone</em> 1 16", 
       "score": 1.6111489e-8 
       }, 
       { 
       "text": "i ip ipo iphon iphon 1 16", 
       "highlighted": "i ip ipo <em>iphon iphon</em> 1 16", 
       "score": 1.4219211e-8 
       }, 
       { 
       "text": "i ip ipo ipho iphone 1 16", 
       "highlighted": "i ip ipo <em>ipho iphone</em> 1 16", 
       "score": 1.3510152e-8 
       }, 
       { 
       "text": "i ip ipo ipho iphon 1 16", 
       "highlighted": "i ip ipo <em>ipho iphon</em> 1 16", 
       "score": 1.1923397e-8 
       }, 
       { 
       "text": "i ip ipo iron iphone 1 16", 
       "highlighted": "i ip ipo <em>iron iphone</em> 1 16", 
       "score": 6.443544e-9 
       } 
      ] 

    **From the document i should use this for phrase suggester.** 

    "mappings": { 
     "test": { 
      "properties": { 
      "title": { 
       "type": "text", 
       "fields": { 
       "trigram": { 
        "type": "text", 
        "analyzer": "trigram" 
       }, 
       "reverse": { 
        "type": "text", 
        "analyzer": "reverse" 
       } 
       } 
      } 
      } 

**How can i use two different mapping on same filed?** 

回答

0
  • 當你的結果不正確標記化問題可能是從 您aurocomplete分析。請提供您的_settings以查看您的分析儀的定義 。

  • 上做您的查詢name.trigram

  • 解決這一問題後,它是很好的使用collate
+0

我加入了一個新的filed.How我可以用短語建議者來此設置預測拼寫錯誤的單詞? 「name_suggest」:{ 「類型」: 「文本」, 「字段」:{ 「反向」:{ 「類型」: 「文本」, 「分析器」: 「反向」 }, 「 trigram「:{ 」type「:」text「, 」analyzer「:」trigram「 } } } –

0

你可以寫這樣的查詢修剪你的結果。請爲此查詢提供輸出。
這也是件好事,你trigram analyzer設置(標記生成器字符映射 S和令牌過濾 S)

{ 
    "suggest": { 
     "text": "noble prize", 
     "simple_phrase": { 
     "phrase": { 
      "field": "name_suggest.trigram", 
      "size": 1, 
      "gram_size": 3, 
      "direct_generator": [ 
       { 
        "field": "name_suggest.trigram", 
        "suggest_mode": "always" 
       } 
      ], 
      "collate": { 
       "query": { 
        "inline": { 
        "match": { 
         "title": "{{suggestion}}" 
        } 
        } 
       }, 
       "prune": true 
      }, 
      "highlight": { 
       "pre_tag": "<em>", 
       "post_tag": "</em>" 
      } 
     } 
     } 
    } 
} 
相關問題