0

I want to run query using python elasticsearch client

GET /employee-index/_search
{
  "size":0,
  "aggs": {
    "genres": {
      "terms": { "field": "gender.keyword" }
    }
  }
}

This is what I am doing but it is returning me the records

es = Elasticsearch()
s = Search(using=es, index="employee-index").aggs.bucket('gender', 'terms', field='gender.keyword')
s = s.execute()
print (s)

It I look at the query running to ES it only has aggs count. I couldn't find in the documentation how to set size to 0 for returning only the aggregation. I try setting but it doesn't work.

Search(using=es, index="employee-index").aggs.bucket('gender', 'terms', field='gender.keyword', size=0)
harshit
  • 7,925
  • 23
  • 70
  • 97

1 Answers1

0

You can use s[0] to have the aggregation count only:

es = Elasticsearch()
s = Search(using=es, index="employee-index")
s = s[0]
s.aggs.bucket('gender', 'terms', field='gender.keyword')
hits = s.execute()

print(hits)
Reyhaneh Torab
  • 360
  • 5
  • 9