Search part of string with ElasticSeach

随声附和 提交于 2019-12-13 05:00:42

问题


In ElasticSearch, I tried to makeit search for a part of a word. My example data is

{
  "_id" : "1",
  "name" : "Nopales",
}
{
  "_id" : "2",
  "name" : "ginger ale",
}
{
  "_id" : "3",
  "name" : "Kale",
}
{
  "_id" : "4",
  "name" : "Triticale Flour Whole Grain",
} 

and the request is to find the matching words with the word "ale is"

GET /_search
{
    "query": {
                "query_string" : {"default_field" : "name", "query" : "*ale*"}
            } 

}

and it returns the results like

Kale, Triticale Flour Whole Grain, ginger ale, Nopales

but the best match is ginger ale, which contains the exact word, then kale, then nopales based on word counts then Triticale Flour Whole Grain. Anyone have idea how to achieve this?


回答1:


I think you should use *ale . In your query it searching for ale in all values of name field. And these all values Kale, Triticale Flour Whole Grain, ginger ale, Nopales contains ale. When you will query with *ale, It will search for string which ending with ale. You can also use like this "query" : "(*ale)OR(ale*)" for different kind of wildcards.



来源:https://stackoverflow.com/questions/51590179/search-part-of-string-with-elasticseach

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!