0

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?

Vidya L
  • 2,289
  • 4
  • 27
  • 42

1 Answers1

0

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.

Ashish Tiwari
  • 1,919
  • 1
  • 14
  • 26