oderfla
oderfla

Reputation: 1797

Cannot get only number of hits in elastic search

Im using _msearch api to send multiple queries to elastic. I only need to know how many hits generates each query. What I understood, you can use the size parameter by setting it to "0" in order to only get the count. However, I still get results with all the found documents. Here is my query:

{"index":"myindex","type":"things","from":0,,"size":0}
{"query":{"bool":{"must":[{"match_all":{}}],"must_not":[],{"match": 
{"firstSearch":true}}]}}}, "size" : 0}
{"index":"myindex","type":"things","from":0,,"size":0}
{"query":{"bool":{"must":[{"match_all":{}}],"must_not":[],{"match": 
{"secondSearch":true}}]}}}, "size" : 0}

Im using curl to get the results, this way:

curl -H "Content-Type: application/x-ndjson" -XGET localhost:9200/_msearch?pretty=1 --data-binary "@requests"; echo

Upvotes: 0

Views: 1189

Answers (2)

pvnam93
pvnam93

Reputation: 1

You can use

GET /indexname/type/_count? { "query": { "match_all": {} } }

please read more document: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-count.html

Upvotes: 0

Srikanta
Srikanta

Reputation: 1147

Setting size as zero signifies that you are asking Elasticsearch to return all the documents which satisfies the query.

You can let Elasticsearch know that you do not need the documents by sending "_source" as false.

Example:

{
  "query": {},
  "_source": false,
}

Upvotes: 3

Related Questions