# Boost Custom Sort According to Query

**URL:** <https://discuss.elastic.co/t/boost-custom-sort-according-to-query/5028>\
**Category:** Elasticsearch\
**Created:** [August 2, 2011, 10:57am UTC](https://discuss.elastic.co/t/boost-custom-sort-according-to-query/5028 "2011-08-02T10:57:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![davrob](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@davrob](https://discuss.elastic.co/u/davrob)\
**Post date:** [August 2, 2011, 10:57am UTC](https://discuss.elastic.co/t/boost-custom-sort-according-to-query/5028/1 "2011-08-02T10:57:20Z")

</div>

Hi,

My queries consist of multiple queries:

i) A Text Prefix Query on fields (firstname, lastname)  
ii) A StringQuery on field (companyname)

I would like to have:

```
1. all results from i) before the results from ii).
2. query i) sorted by one field (person_name) and results from

```

query ii) sorted by another (company\_\_name)

The only way I can think of doing this is firstly to identify which  
query a result comes from and apply a custom sort to acheive the above

i.e sort results from i) by person\_name and then multiple all results  
scores from i) by 1,000,000  
sort results from ii) by companyName and then divide all results  
scores from ii) by 1,000,000

Is there any way I can identify which query a result has come from in  
the custom sort?

Ideally I would apply sorts at the query (QueryBuilder) level and then  
apply a boost (i.e. 1,000,000) using CustomBoostFactorQueryBuilder but  
it is not possible to sort on QueryBuilder instances only on  
SearchRequestBuilder, as far as I can tell, if anyone know of a way of  
doing that then that would be even better.

Best Regards,

David.

---

<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:** [July 6, 2017, 3:58am UTC](https://discuss.elastic.co/t/boost-custom-sort-according-to-query/5028/2 "2017-07-06T03:58:31Z")

</div>


