# Efficient way to sort by different fields by client

**URL:** <https://discuss.elastic.co/t/efficient-way-to-sort-by-different-fields-by-client/248206>\
**Category:** Elasticsearch\
**Created:** [September 10, 2020, 4:48pm UTC](https://discuss.elastic.co/t/efficient-way-to-sort-by-different-fields-by-client/248206 "2020-09-10T16:48:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![taichi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/taichi/32/46431_2.png) [@taichi](https://discuss.elastic.co/u/taichi)\
**Post date:** [September 10, 2020, 4:48pm UTC](https://discuss.elastic.co/t/efficient-way-to-sort-by-different-fields-by-client/248206/1 "2020-09-10T16:48:17Z")

</div>

I have an index named `items` . And we have many stores (now around 100, and in the future it may be 10,000) .

Each item has a price for each store. So item document may look like this:

```
{
  "item_id": 1,
  "description": "This is a nice item."
  "store1_price": 100,
  "store2_price": 111,
  "store3_price": 122,
  ...
  "store100_price": 200
}

```

Sometimes I sort them by `store2_price`, and sometimes by `store999_price`.

This strategy does not seem an efficient way, because number of `storeN_price` increases as we have more and more stores (maybe `store10000_price` ?).

We can put prices into a nested field, but it does not change things a lot.

Any efficient ideas to refactor this `items` index?  
(Maybe we have to divide index, or use other middlewares)

---

<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:** [October 8, 2020, 4:48pm UTC](https://discuss.elastic.co/t/efficient-way-to-sort-by-different-fields-by-client/248206/2 "2020-10-08T16:48:21Z")

</div>

Closed on October 8, 2020, 4:48pm UTC

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