2016-09-21 69 views
0

我們使用elasticsearch正在執行搜索公司名單,但它不是我們所期望的Elasticsearch優化查詢

**Example companies:**  
Infosys technologies   
Infosys technologies ltd   
Infosys technologies pvt ltd   
Infosys technologies Limited   
Infosys technologies Private Limited   
BAC Infosys ltd 

場景:

  1. 當搜索關鍵字「Infosys公司」,它應該返回「印孚瑟斯 技術「列表。

  2. 當搜索關鍵字「Infosys ltd」時,應返回「Infosys technologies」列表。

  3. 當搜索關鍵字「BAC Infosys ltd」時,應返回「BAC Infosys ltd」列表。

以下設置和映射使用

{ 
    "settings": { 
     "analysis": { 
     "filter": { 
      "nGram_filter": { 
       "type": "nGram", 
       "min_gram": 3, 
       "max_gram": 3, 
       "token_chars": [ 
        "letter", 
        "digit", 
        "punctuation", 
        "symbol" 
       ] 
      } 
     }, 
     "analyzer": { 
      "nGram_analyzer": { 
       "type": "custom", 
       "tokenizer": "keyword", 
       "filter": [ 
        "lowercase", 
        "asciifolding", 
        "nGram_filter" 
       ] 
      }, 
      "keyword_analyzer": { 
       "type": "custom", 
       "tokenizer": "keyword", 
       "filter": [ 
        "lowercase", 
        "asciifolding" 
       ] 
      } 
     } 
     } 
    }, 
    "mappings": { 
     "companies": { 
      "properties": { 
       "company_name": { 
        "type": "string", 
        "store": "true", 
        "index_analyzer": "nGram_analyzer", 
        "search_analyzer": "keyword_analyzer", 
        "null_value": "null" 
       } 
      } 
     } 
    } 
} 

查詢:

{"query": 
    { 
     "bool": { 
     "must": [ 
      { "match": { "company_name": "Infosys technologies" }} 
     ], 
     "minimum_should_match": "80%" 
     } 
    } 
} 

請幫助我如何實現這一目標。

回答

0

您在搜索查詢和映射方面都缺少一些東西。在您的場景中使用當前映射設置並使用當前映射設置 1)結果也將具有BAC值。您應該切換到邊緣n-grams。但這不會讓您從中間搜索。 2)它也取決於你正在建立什麼類型的搜索,你可以避免我在1中提出的安排。對於你的所有場景,讓我們假設你的列表在結果中也可以有BAC值,但在列表中排名較低。爲此,您可以使用proximity queries模糊查詢進行拼寫檢查。

以上三種情況下,不會向我解釋整個功能,並且會爲您的搜索功能使用-case,但我認爲由elastic提供的鄰近搜索可以讓您更靈活地滿足您的案例。

+0

你可以給我任何例子,因爲我是Elasticsearch的新手。請幫助我 – azhagu