Python Elasticsearch: how to include the query `search_type = count` in the query?

I have a Python script that runs many ElasticSearch aggregates, for example:

client = Elasticsearch(...)
q =  {"aggs": {"my_name":{"terms": "field", "fieldname"}}}
res = client.search(index = "indexname*", doc_type = "doc_type", body = q)

But this returns a search query (match everything I think) res["hits"]and aggregation results res["aggregations"].

What I want to run is the Python equivalent of the following

GET /index*/doc_type/_search?search_type=count

{"aggs": {"my_name":{"terms": "field", "fieldname"}}}

How can I enable ?search_type=countwhen using Python Elasticsearch?

I would like to know this in general, but the current reason I look at it, I sometimes get errors caused by timeouts or data size when starting queries. My suspicion is that if I can only ask for a count, then I will avoid them.

+4
source share
2

, search_type=count, 2.0. size: 0.

res = client.search(index = "indexname*", doc_type = "doc_type", body = q, size=0)
                                                                             ^
                                                                             |
                                                                         add this
+10

-

res = client.search(index = "indexname*", doc_type = "doc_type", body = q, search_type='count')

@Val, ES 2.x

+1

Source: https://habr.com/ru/post/1616759/


All Articles