# Python3 + elasticsearch\_dsl good resources/examples simple query problem

**URL:** <https://discuss.elastic.co/t/python3-elasticsearch-dsl-good-resources-examples-simple-query-problem/264199>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [February 13, 2021, 3:01am UTC](https://discuss.elastic.co/t/python3-elasticsearch-dsl-good-resources-examples-simple-query-problem/264199 "2021-02-13T03:01:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stcdarrell](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@stcdarrell](https://discuss.elastic.co/u/stcdarrell)\
**Post date:** [February 13, 2021, 3:01am UTC](https://discuss.elastic.co/t/python3-elasticsearch-dsl-good-resources-examples-simple-query-problem/264199/1 "2021-02-13T03:01:04Z")

</div>

i'm fighting to get over the hump of gaining competence with elasticsearch\_dsl for python.

i'm trying to do my end of the year (2020) reports.. and i have a set of indexes that total about 3/4 of a billion records. i need all the unqiue values and the count of those values.

using the dev interface its a simple query.. but you cant get all the results easily.

POST /lookout-hp\*/\_search?size=0  
{  
"size": 0,  
"aggs" : {  
"langs" : {  
"terms" : { "field" : "password.keyword", "size" : 50000 }  
}  
}}

results:  
{  
"took" : 4221,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 115,  
"successful" : 115,  
"skipped" : 0,  
"failed" : 0  
},  
"hits" : {  
"total" : {  
"value" : 10000,  
"relation" : "gte"  
},  
"max\_score" : null,  
"hits" :   
},  
"aggregations" : {  
"langs" : {  
"doc\_count\_error\_upper\_bound" : 0,  
"sum\_other\_doc\_count" : 376068,  
"buckets" : [  
{  
"key" : "password",  
"doc\_count" : 349639  
},  
{  
"key" : "admin",  
"doc\_count" : 254823  
},  
{  
"key" : "123456",  
"doc\_count" : 200632  
},  
{  
"key" : "",  
"doc\_count" : 186228  
},  
{  
"key" : "1234",  
"doc\_count" : 110466  
},  
{  
"key" : "root",  
"doc\_count" : 92418  
},  
...

how do i do this in elasticsearch\_dsl and python to get all the results? i cant find any good examples.  
are there any other good resources? online or a book?

thank you

---

<div class="post-metadata">

**Author:** ![stcdarrell](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@stcdarrell](https://discuss.elastic.co/u/stcdarrell)\
**Post date:** [February 13, 2021, 5:59pm UTC](https://discuss.elastic.co/t/python3-elasticsearch-dsl-good-resources-examples-simple-query-problem/264199/2 "2021-02-13T17:59:27Z")

</div>

i got the responses i want with this python code:

```
    s = Search(using=client, index="lookout-hp-*")
    s.aggs.bucket('per_tag','terms', field='password.keyword')
    response=s.execute()
    s_Data=s.to_dict()
    print (s_Data)
    r_Data=response.aggregations.per_tag.to_dict()
    print (r_Data)

```

i have millions of responses.. and i know i need to page or scan through them to get them all.. but i sure cant find an example of that.. any suggestions would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![stcdarrell](https://avatars.discourse-cdn.com/v4/letter/s/a183cd/32.png) [@stcdarrell](https://discuss.elastic.co/u/stcdarrell)\
**Post date:** [February 16, 2021, 3:15pm UTC](https://discuss.elastic.co/t/python3-elasticsearch-dsl-good-resources-examples-simple-query-problem/264199/3 "2021-02-16T15:15:17Z")

</div>

got it.. just didnt know the right terms .. i needed a "composite aggregation" the link below works perfectly.

> <https://github.com/elastic/elasticsearch-dsl-py/blob/master/examples/composite_agg.py>

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [February 16, 2021, 10:57pm UTC](https://discuss.elastic.co/t/python3-elasticsearch-dsl-good-resources-examples-simple-query-problem/264199/4 "2021-02-16T22:57:21Z")

</div>

Thanks for sharing your solution, and good luck! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 16, 2021, 10:57pm UTC](https://discuss.elastic.co/t/python3-elasticsearch-dsl-good-resources-examples-simple-query-problem/264199/5 "2021-03-16T22:57:42Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
