i want to send query to ELS that return only the total hits.
without anything else
like if i get the respone
{ "took": 1111, "timed_out": false, "_shards": {
"total": 9,
"successful": 9,
"failed": 0 }, "hits": {
"total": 731552,
}
i want to print only 731552
for now i just send :
curl http://server:9200/games_profilder/_search
thanks
The track_total_hits parameter allows you to control how the total number of hits should be tracked. Given that it is often enough to have a lower bound of the number of hits, such as "there are at least 10000 hits", the default is set to 10,000 .
If a search request results in more than ten hits, ElasticSearch will, by default, only return the first ten hits. To override that default value in order to retrieve more or fewer hits, we can add a size parameter to the search request body.
You can use cURL in a UNIX terminal or Windows command prompt, the Kibana Console UI, or any one of the various low-level clients available to make an API call to get all of the documents in an Elasticsearch index. All of these methods use a variation of the GET request to search the index.
You can use response filtering for this:
curl http://server:9200/games_profilder/_search?filter_path=hits.total
which will yield
{
"hits": {
"total": 731552
}
}
If you really want to only get the total, you can pipe the result with jq
like this:
curl http://server:9200/games_profilder/_search?filter_path=hits.total | jq '.hits.total'
and that will yield only the number 731552
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With