Is it possible to return all ids from an Elasticsearch search keeping the specified `size`?

Asked

Viewed 27 times

0

It is possible to return all ids of an Elasticsearch search?

I have the following query that most of the time returns in the field ['hits']['total'] more hits than what I specify on size.

As in the example:

query_body = {
    "from": 0,
    "size": 40,
    "query": {
        "bool": {
            "should": [
                {
                    "multi_match":{
                        "query": 'caderno preto',
                        "fields":[
                            "DescricaoSEO",
                            "TermoBusca",
                            "Fabricante"
                        ],
                        "minimum_should_match":"100%",
                    }
                }
            ],
            "must": []
        }
    }
}

My query returns the first 40 hits, but when I print the total of hits I have:

print(retornoES['hits']['total'])
{'value': 426, 'relation': 'eq'}

Is there any way to return all the 426 _id in the consultation keeping the size of the first 40?

1 answer

0

After some searches I managed to assemble the following query.

GET meuindex/_search
{
   "from":0,
   "size":40,
   "query":{
      "bool":{
         "should":[
            {
               "multi_match":{
                  "query":"pincel branco bic",
                  "fields":[
                     "DescricaoSEO",
                     "TermoBusca",
                     "Fabricante",
                     "Codigo"
                  ],
                  "minimum_should_match":"100%"
               }
            }
         ]
      }
   },
   "aggs":{
      "Codigo Filter":{
         "terms":{
            "field":"Codigo.keyword",
            "size":10000
         }
      }
   }
}

This returns me an aggregation of my codes that are the same as the _id field

inserir a descrição da imagem aqui

Browser other questions tagged

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