# User specific ranking

**URL:** <https://discuss.elastic.co/t/user-specific-ranking/143529>\
**Category:** Elasticsearch\
**Created:** [August 8, 2018, 1:54pm UTC](https://discuss.elastic.co/t/user-specific-ranking/143529 "2018-08-08T13:54:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kurt1](https://avatars.discourse-cdn.com/v4/letter/k/e274bd/32.png) [@kurt1](https://discuss.elastic.co/u/kurt1)\
**Post date:** [August 8, 2018, 1:54pm UTC](https://discuss.elastic.co/t/user-specific-ranking/143529/1 "2018-08-08T13:54:06Z")

</div>

I'm very new to elasticsearch and would like some guidance on the best approach to handle my problem.

I have a million articles that I want to search. Each article is ranked beforehand for each user using a custom function. That means every article has as many scores as there are users. When searching I want to rank the returned articles according to the custom scores of one particular user. What's the best way to store a (possibly) unlimited amount of scores for each article?

How do I implement this in a way that is scalable and supported by elasticsearch?

All ideas I came up with don't seem to fit the way elasticsearch is meant to be used.

- **IDEA 1:** Store an array of scores on each article. Each index represents a score for one user. When getting results for user-id 42 I simply rank by the 42nd element in my arrays.  
_PROBLEM:_ Arrays don't work as expected. They have no order. According to [this](https://stackoverflow.com/questions/47002146/elasticsearch-sort-by-first-element-of-array) I would need to read that value from disk every time for every article (slow), or use the `nested` datatype which has a maximum nesting level (hence doesn't scale).
- **IDEA 2:** Create separate fields for each score on an article. E.g. "score\_user\_1", "score\_user\_2", ... This way I can dynamically compose my field from the user-id and then simply sort the results by that field.  
_PROBLEM:_ I don't think I should create an unlimited amount of fields per document. By default the max number of fields is set to 1000. What if I someday have 100,000 users? Would this still work? Up until which point? It feels to me like this is not how elasticsearch works.
- **IDEA 3:** Create a parent-child relation between article and score. When searching I could join all articles with their childs (i.e. scores) that belong to the given user-id. Then articles are sorted based on the value stored in their child.  
_PROBLEM:_ The [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html) says that joining is very slow and should be avoided at all costs. If one really must use it, it should be used as little as possible. I would be using it in the millions.

---

<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:** [September 5, 2018, 1:54pm UTC](https://discuss.elastic.co/t/user-specific-ranking/143529/2 "2018-09-05T13:54:33Z")

</div>

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