# Query for subset: what Lego project can I build using only pieces I own?

**URL:** <https://discuss.elastic.co/t/query-for-subset-what-lego-project-can-i-build-using-only-pieces-i-own/2505>\
**Category:** Elasticsearch\
**Created:** [June 11, 2015, 6:23pm UTC](https://discuss.elastic.co/t/query-for-subset-what-lego-project-can-i-build-using-only-pieces-i-own/2505 "2015-06-11T18:23:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lev/32/630_2.png) [@lev](https://discuss.elastic.co/u/lev)\
**Post date:** [June 11, 2015, 6:23pm UTC](https://discuss.elastic.co/t/query-for-subset-what-lego-project-can-i-build-using-only-pieces-i-own/2505/1 "2015-06-11T18:23:18Z")

</div>

I'm having trouble figuring out how to construct a query that works something like this. Let's say a user has a bunch of lego pieces and they want to find out what projects they can build that use all or some of the user's pieces but don't use any they don't have.

I already have a nested document setup with piece id and quantity, how do I structure the query so that it returns projects that use pieces that are a subset of the user's library?

[![](http://media.giphy.com/media/103TZqgLqRJq0M/giphy.gif) ](http://media.giphy.com/media/103TZqgLqRJq0M/giphy.gif)

Thank you.

---

<div class="post-metadata">

**Author:** ![lev](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lev/32/630_2.png) [@lev](https://discuss.elastic.co/u/lev)\
**Post date:** [June 15, 2015, 4:06pm UTC](https://discuss.elastic.co/t/query-for-subset-what-lego-project-can-i-build-using-only-pieces-i-own/2505/2 "2015-06-15T16:06:06Z")

</div>

I ended up indexing each project with pieces it is made out of and pieces it doesn't use. Then I query for all pieces it `must` not contain and for pieces it `should` contain.

---

<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:** [July 6, 2017, 12:07am UTC](https://discuss.elastic.co/t/query-for-subset-what-lego-project-can-i-build-using-only-pieces-i-own/2505/3 "2017-07-06T00:07:24Z")

</div>


