# Returning a subset of documents

**URL:** <https://discuss.elastic.co/t/returning-a-subset-of-documents/72090>\
**Category:** Elasticsearch\
**Created:** [January 18, 2017, 9:14pm UTC](https://discuss.elastic.co/t/returning-a-subset-of-documents/72090 "2017-01-18T21:14:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmdev](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@dmdev](https://discuss.elastic.co/u/dmdev)\
**Post date:** [January 18, 2017, 9:14pm UTC](https://discuss.elastic.co/t/returning-a-subset-of-documents/72090/1 "2017-01-18T21:14:44Z")

</div>

Hi there,

I have the following scenario where I don't know a solution yet.

Imagine you have your typical users on a website. Each user has a collection of objects. These objects have several attributes and belong to a set A. Given you have a subset B (with a very small cardinality - e.g. |B| = 5) of A and you want to return the users which have most of the objects in B, how would you set up your index in ES?  
Example: A = {obj1, obj2,...,obj100}; user1 has {obj1, obj67, obj77}; user2 has { obj1, obj44, obj54}; B={obj1, obj67}. Then ES should return user1 before user2.

My idea is to create an index where a document has the attributes of the objects and a user\_id.  
A filter should be the right approach.

Any ideas? I hope my explanation was understandable.

---

<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:** [February 15, 2017, 9:14pm UTC](https://discuss.elastic.co/t/returning-a-subset-of-documents/72090/2 "2017-02-15T21:14:50Z")

</div>

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