# Manually adjusting document sort based on queries

**URL:** <https://discuss.elastic.co/t/manually-adjusting-document-sort-based-on-queries/22794>\
**Category:** Elasticsearch\
**Created:** [March 21, 2015, 5:38pm UTC](https://discuss.elastic.co/t/manually-adjusting-document-sort-based-on-queries/22794 "2015-03-21T17:38:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zelfapp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zelfapp/32/108888_2.png) [@Zelfapp](https://discuss.elastic.co/u/Zelfapp)\
**Post date:** [March 21, 2015, 5:38pm UTC](https://discuss.elastic.co/t/manually-adjusting-document-sort-based-on-queries/22794/1 "2015-03-21T17:38:54Z")

</div>

For specific queries I want to be able to manually set the sort of some  
search results. Without going into the reason why, how do I implement this?  
I'm not talking about boosting, I'm talking about manually setting the sort  
position based on specific query.

E.g. if users searches for "Green Military Shirts" I want to set product X  
to position 1, product J to position 2. All other search results would  
sorted as usual.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2757e0a1-ca5a-498e-89e2-02cf3dad9e0e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2757e0a1-ca5a-498e-89e2-02cf3dad9e0e%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Zelfapp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zelfapp/32/108888_2.png) [@Zelfapp](https://discuss.elastic.co/u/Zelfapp)\
**Post date:** [March 21, 2015, 11:11pm UTC](https://discuss.elastic.co/t/manually-adjusting-document-sort-based-on-queries/22794/2 "2015-03-21T23:11:01Z")

</div>

It appears I've answered my own question unless someone has a better  
suggestion in terms of efficiency and logic. The function\_score Query  
([function\_score Query | Elasticsearch: The Definitive Guide [master] | Elastic](http://www.elastic.co/guide/en/elasticsearch/guide/master/function-score-query.html))  
will allow for boosting specific documents based on the query. Several  
different predefined methods or I can create my own custom script.

On Saturday, March 21, 2015 at 10:38:54 AM UTC-7, Zelfapp wrote:

> For specific queries I want to be able to manually set the sort of some  
> search results. Without going into the reason why, how do I implement this?  
> I'm not talking about boosting, I'm talking about manually setting the sort  
> position based on specific query.
> 
> E.g. if users searches for "Green Military Shirts" I want to set product X  
> to position 1, product J to position 2. All other search results would  
> sorted as usual.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/fb45a9a8-076a-4d9c-af62-887ce3508382%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fb45a9a8-076a-4d9c-af62-887ce3508382%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [March 22, 2015, 2:16pm UTC](https://discuss.elastic.co/t/manually-adjusting-document-sort-based-on-queries/22794/3 "2015-03-22T14:16:15Z")

</div>

Easiest option, in terms of complexity, would probably be to use a bool  
query, where product x and y are matched by an id query with high boosts.

Best option is probably the function score query:

> **[Function score query | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html)**

Create a filter for each product and replace the score with something  
arbitrarly high.

You could get detailed by using a custom script, but it will not be as  
efficient.

Cheers,

Ivan  
On Mar 21, 2015 7:39 PM, "Zelfapp" [nate@usamm.com](mailto:nate@usamm.com) wrote:

> For specific queries I want to be able to manually set the sort of some  
> search results. Without going into the reason why, how do I implement this?  
> I'm not talking about boosting, I'm talking about manually setting the sort  
> position based on specific query.
> 
> E.g. if users searches for "Green Military Shirts" I want to set product X  
> to position 1, product J to position 2. All other search results would  
> sorted as usual.
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/2757e0a1-ca5a-498e-89e2-02cf3dad9e0e%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2757e0a1-ca5a-498e-89e2-02cf3dad9e0e%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/2757e0a1-ca5a-498e-89e2-02cf3dad9e0e%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/2757e0a1-ca5a-498e-89e2-02cf3dad9e0e%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCibunCj15nHP0vNm8gg0U7qukDL%3DUKrmahx-OR9KLhjQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALY%3DcQCibunCj15nHP0vNm8gg0U7qukDL%3DUKrmahx-OR9KLhjQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:25am UTC](https://discuss.elastic.co/t/manually-adjusting-document-sort-based-on-queries/22794/4 "2017-07-06T00:25:08Z")

</div>


