# Python Query DSL | Aggregation partition finder

**URL:** <https://discuss.elastic.co/t/python-query-dsl-aggregation-partition-finder/231453>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [May 7, 2020, 4:38am UTC](https://discuss.elastic.co/t/python-query-dsl-aggregation-partition-finder/231453 "2020-05-07T04:38:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NerdSec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nerdsec/32/22056_2.png) [@NerdSec](https://discuss.elastic.co/u/NerdSec)\
**Post date:** [May 7, 2020, 4:38am UTC](https://discuss.elastic.co/t/python-query-dsl-aggregation-partition-finder/231453/1 "2020-05-07T04:38:05Z")

</div>

Hi Team,

Is there a way to programmatically build a search object and iterate through it's partitions? I am currently doing this by passing an incremental dict to my search object.

```auto
s = Search(using=client)
s = s.filter(**params)
i = 0
j = 100
while i < j:
  partitions = {"partition": i, "num_partitions": j}
  ns = copy.copy(s)
  ns.aggs.bucket('first', 'terms', field='tags.keyword', size=100, include=partitions)
  res = ns.execute()
  index_data(res)

```

Is this the only approach we can take to get all the agg results? Or is there a method we can call?

---

<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:** [June 4, 2020, 4:38am UTC](https://discuss.elastic.co/t/python-query-dsl-aggregation-partition-finder/231453/2 "2020-06-04T04:38:06Z")

</div>

Closed on June 4, 2020, 4:38am UTC

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