Doubt Search in ElasticSearch

2

When searching for a term "xpto no blabla bla" I need to return all items that have "xpto no blablabla" and then, in order of relevance "xpto" "blablabla"

Does anyone have a light?

Thank you

    
asked by anonymous 12.12.2016 / 20:29

2 answers

2

I was able to evolve a bit using minimum_should_match:

GET _search
{
  "query": {
    "match": {
      "nome": {
        "query": "caixa som",
        "minimum_should_match": "95%"
      }
    }
 },
 "size": 15,
 "from": 15
}

but I can not search for more than one field

My idea was: give priority to those who attend "sound box" then come in those that have more relevance: "box" and "sound"

    
13.12.2016 / 14:21
3

To filter by more than one field we use Combining Queries with the multi_match clause that allows us to search for the searched term in more than one field.

"fields":["nome","sobrenome"]

The priority issue is related to the search term in relation to the occurrences in which they appear in the indexed documents. To return the expected result it will be necessary to mount a compound query.

{  
   "size": "15",
   "query":{  
      "bool":{  
         "should":[  
            {  
               "multi_match":{  
                  "query":"caixa som",
                  "fields":[  
                     "nome"
                  ],
                  "type":"phrase",
                  "minimum_should_match": "95%"
               }
            },
            {  
               "multi_match":{  
                  "query":"caixa som",
                  "fields":[  
                     "nome"
                  ]
               }
            }
         ]
      }
   }
}

As a result, the query places the documents that contain the terms "box sound" according to their order and proximity, this is possible because of the phrase / em>, followed by documents that contain "box" or "sound".

    
23.01.2017 / 19:39