# Want. Best practices to solve the sort question with ES

**URL:** <https://discuss.elastic.co/t/want-best-practices-to-solve-the-sort-question-with-es/270502>\
**Category:** Elasticsearch\
**Created:** [April 18, 2021, 4:35pm UTC](https://discuss.elastic.co/t/want-best-practices-to-solve-the-sort-question-with-es/270502 "2021-04-18T16:35:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yout0703](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yout0703/32/87263_2.png) [@yout0703](https://discuss.elastic.co/u/yout0703)\
**Post date:** [April 18, 2021, 4:35pm UTC](https://discuss.elastic.co/t/want-best-practices-to-solve-the-sort-question-with-es/270502/1 "2021-04-18T16:35:10Z")

</div>

I want to sort some entities(A)，each of them is related to another kind of entity(B). Different A has different relation score with B。I want to query A by B and sort them by relation scores。  
some samples for A：

```
{
	"name":"aaa",
	"bEntitys":{
		"b_1": 1,
		"b_2": 3,
		"b_4": 5
	}
}
{
	"name":"ccc",
	"bEntitys":{
		"b_1": 1,
		"b_3": 3,
		"b_5": 5
	}
}
{
	"name":"eee",
	"bEntitys":{
		"b_2": 1,
		"b_3": 3,
		"b_4": 5,
		"b_5": 8,
		"b_6": 0,
		"b_7": 3
	}
}
{
	"name":"fff",
	"bEntitys":{
		"b_1": 1
	}
}

```

At present, I import the `bEntitys` field into ES with `Object` type and indexed them. so,I can search them with the logic of:(search b\_1,for example)

1. Filter: field `bEntitys.b_1` is exist.
2. Sort: get `bEntitys.b_1`'s score for sort.

Question is that, every key of `bEntitys` will be the field of the current index(json field will be paved). when there is a lot of B,it is going to exceed the maximum limit of index fields.

In addition, may be `script` can do this，but Its performance is not good.  
Is there any other ways?  
Thanks.

---

<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:** [May 16, 2021, 4:35pm UTC](https://discuss.elastic.co/t/want-best-practices-to-solve-the-sort-question-with-es/270502/2 "2021-05-16T16:35:52Z")

</div>

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