Doubt Search in Elasticsearch

Asked

Viewed 292 times

3

when searching for a term "foo in Blabla bla" I need to return all items that have "blablah blah" and then in order of relevance "foo" "blablah"

someone has a light?

Thank you

2 answers

4

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

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

The priority question is related to the search term in relation to the occurrences in which they appear in the indexed documents. To return the expected result you will need to assemble a composite 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 with greater relevance (score) documents containing the terms "sound box" obeying their order and proximity, this is possible because of the clause Phrase, followed by documents containing "box" or "sound".

3


I managed to evolve a little using minimum_should_match:

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

but I can’t search for more than one field

my idea was: give priority to those who attend "sound box" then come to the ones that have more relevance: "box" and "sound"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.