2016-06-07 40 views
1

这是我的DSL:如何搜索产品与elasticsearch

{ 
    "query": { 
    "function_score": { 
     "query": { 
     "multi_match": { 
      "query": "testa", 
      "analyzer":"standard", 
      "type": "best_fields", 
      "fields": [ "name^5", "content^1" ] 
     } 
     }, 
     "field_value_factor": { 
     "field": "popular", 
     "modifier": "log1p", 
     "factor": 0.1 
     }, 
     "boost_mode": "sum", 
     "max_boost": 1.5 
    } 
    } 
} 

当我搜索像“种皮”这样的关键字,结果只包含关键字“种皮”,我应该怎么做才能使结果中包含关键字'testa'和'test'或'tes'? 谢谢。

回答

0

您可以使用Fuzzy Match Query您的查询就会像:

{ 
    "query": { 
    "function_score": { 
     "query": { 
     "multi_match": { 
      "query": "testa", 
      "analyzer":"standard", 
      "fuzziness":"3", 
      "type": "best_fields", 
      "fields": [ "name^5", "content^1" ] 
     } 
     }, 
     "field_value_factor": { 
     "field": "popular", 
     "modifier": "log1p", 
     "factor": 0.1 
     }, 
     "boost_mode": "sum", 
     "max_boost": 1.5 
    } 
    } 
} 

此外,Simple Query String Query可以帮助,但你必须输入你的用语为“TES *”,这可能会或可能不会被您的使用情况所接受。