2016-09-21 70 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