# Is it possible to extract subset of bucket1, where bucket1 has the same value as bucket2 on different fields?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-extract-subset-of-bucket1-where-bucket1-has-the-same-value-as-bucket2-on-different-fields/154285>\
**Category:** Elasticsearch\
**Created:** [October 27, 2018, 11:38am UTC](https://discuss.elastic.co/t/is-it-possible-to-extract-subset-of-bucket1-where-bucket1-has-the-same-value-as-bucket2-on-different-fields/154285 "2018-10-27T11:38:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![helloWorldJS](https://avatars.discourse-cdn.com/v4/letter/h/eb9ed0/32.png) [@helloWorldJS](https://discuss.elastic.co/u/helloWorldJS)\
**Post date:** [October 27, 2018, 11:38am UTC](https://discuss.elastic.co/t/is-it-possible-to-extract-subset-of-bucket1-where-bucket1-has-the-same-value-as-bucket2-on-different-fields/154285/1 "2018-10-27T11:38:46Z")

</div>

hey folks,  
I've tried to summarize my idea in the title.

My thought was to get a subset of a bucket:  
for example: there ar two buckets:  
in both of the buckets i have a set of documents.  
bucket1 is complete. Now iwant all the documents of bucket2, where the value of bucket2.someField === bucket1.another\_notTheSameField.  
Can anybody help?

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [October 29, 2018, 11:36am UTC](https://discuss.elastic.co/t/is-it-possible-to-extract-subset-of-bucket1-where-bucket1-has-the-same-value-as-bucket2-on-different-fields/154285/2 "2018-10-29T11:36:52Z")

</div>

Hard to say without a more concrete example, but you can embed a second aggregation inside the first which has some further limiting criteria.

E.g. first aggregation is a terms aggregation on `field: foo`. All documents in the bucket will have the same value for the field `foo`. If you put a second aggregation inside the first (like a [filter aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html)), you'll get a filtered subset of the documents.

---

<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:** [November 26, 2018, 11:41am UTC](https://discuss.elastic.co/t/is-it-possible-to-extract-subset-of-bucket1-where-bucket1-has-the-same-value-as-bucket2-on-different-fields/154285/3 "2018-11-26T11:41:41Z")

</div>

Closed on November 26, 2018, 11:41am UTC

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