# Uncommonly common recommendation based on page view stats

**URL:** <https://discuss.elastic.co/t/uncommonly-common-recommendation-based-on-page-view-stats/142729>\
**Category:** Elasticsearch\
**Created:** [August 2, 2018, 9:39am UTC](https://discuss.elastic.co/t/uncommonly-common-recommendation-based-on-page-view-stats/142729 "2018-08-02T09:39:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![outlookvineet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/outlookvineet/32/34008_2.png) [@outlookvineet](https://discuss.elastic.co/u/outlookvineet)\
**Post date:** [August 2, 2018, 9:39am UTC](https://discuss.elastic.co/t/uncommonly-common-recommendation-based-on-page-view-stats/142729/1 "2018-08-02T09:39:52Z")

</div>

Hi,  
My question is reference to the example given in following post on significant terms use case  
[https://www.elastic.co/guide/en/elasticsearch/guide/current/\_significant\_terms\_demo.html#\_recommending\_based\_on\_statistics](https://www.elastic.co/guide/en/elasticsearch/guide/current/_significant_terms_demo.html#_recommending_based_on_statistics)

I have similar requirement, but it is about events instead of movies. So to answer "People who saw this event page have also saw these other events" (based on page views)

So far so good. Now, the problem is that I index the data little differently.  
I have an index to store each page view as separate document which also contains all the data about event and user who saw the page

So, every time some user views an event page, I store following field  
page\_view\_id  
page\_view\_timestamp  
event\_id  
event\_name  
user\_id  
user\_name  
...  
....

Now, I would like to recommend "People who saw this event page also viewed these events" using significant terms aggregation. But in my case I have to first get list of users who viewed the current event page, and then do another query for finding other events (but uncommonly common) viewed by all those users.  
Is there a way to do that in a single query ?  
Moreover, the list of users returned from first query could be in thousands. So doing a second query with filter of that many user ids would again be very.

How should I approach this ?

Thank you

---

<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:** [August 2, 2018, 11:13am UTC](https://discuss.elastic.co/t/uncommonly-common-recommendation-based-on-page-view-stats/142729/2 "2018-08-02T11:13:33Z")

</div>

Behavioural analysis is most easily attempted on an _entity-centric index_ rather than the sort of _event-centric index_ in your example (which looks typical of most logging applications).

See [1] for background on the approach and the example data/scripts [2]

In your case the entity is identified by the `user_id` and each user doc should hold an array of things viewed which are not movies but `event_id` numbers mapped as the `keyword` type.

[1] [https://www.youtube.com/watch?v=yBf7oeJKH2Y](https://www.youtube.com/watch?v=yBf7oeJKH2Y)  
[2] [https://www.dropbox.com/s/npnopvcdobpprdw/EntityCentricDemo6.3.zip](https://www.dropbox.com/s/npnopvcdobpprdw/EntityCentricDemo6.3.zip)

---

<div class="post-metadata">

**Author:** ![outlookvineet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/outlookvineet/32/34008_2.png) [@outlookvineet](https://discuss.elastic.co/u/outlookvineet)\
**Post date:** [August 2, 2018, 2:12pm UTC](https://discuss.elastic.co/t/uncommonly-common-recommendation-based-on-page-view-stats/142729/3 "2018-08-02T14:12:05Z")

</div>

Thanks Mark,  
I'll go with the approach as suggested by you.

---

<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:** [August 30, 2018, 2:12pm UTC](https://discuss.elastic.co/t/uncommonly-common-recommendation-based-on-page-view-stats/142729/4 "2018-08-30T14:12:11Z")

</div>

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