# Use aggregation to recommend items

**URL:** <https://discuss.elastic.co/t/use-aggregation-to-recommend-items/234385>\
**Category:** Elasticsearch\
**Created:** [May 26, 2020, 4:26pm UTC](https://discuss.elastic.co/t/use-aggregation-to-recommend-items/234385 "2020-05-26T16:26:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kushikawa](https://avatars.discourse-cdn.com/v4/letter/k/8baadc/32.png) [@Kushikawa](https://discuss.elastic.co/u/Kushikawa)\
**Post date:** [May 26, 2020, 4:26pm UTC](https://discuss.elastic.co/t/use-aggregation-to-recommend-items/234385/1 "2020-05-26T16:26:33Z")

</div>

I have **order** objects indexed with the client id and the order's items.  
I'd like to know what products recommend to a client based on the items he bought, using a collaborative filtering

I'm new to elasticsearch, and I'm following the example from here [https://qbox.io/blog/building-simple-recommender-systems-for-elasticsearch-1](https://qbox.io/blog/building-simple-recommender-systems-for-elasticsearch-1) but I still don't know how to personalize my query based on:

[1] I don't want to make two requests, one to get the items he bought and then construct the query filter in agreggation. I'd like to make a query inside the filter that gets all items a cliente has bought even they are from different orders.

[2] I also want to make a personalized filter, based on combinations of items, since having orders containing all the items a client has purchased is practically impossible.  
e.g, a client has a purchase history of 5 products (in different orders), so I want to boost results like:

- products from orders that have those 5 items have a greater score
- products from orders that have 4 of those 5 items have a slightly lower score
- and so on

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [May 26, 2020, 9:14pm UTC](https://discuss.elastic.co/t/use-aggregation-to-recommend-items/234385/2 "2020-05-26T21:14:47Z")

</div>

> [@Kushikawa](#):
>
> don't want to make two requests,

This constraint is unsupportable - especially if a customer's orders are distributed across multiple nodes/shards.

---

<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 23, 2020, 9:14pm UTC](https://discuss.elastic.co/t/use-aggregation-to-recommend-items/234385/3 "2020-06-23T21:14:51Z")

</div>

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