# Conditional function score query

**URL:** <https://discuss.elastic.co/t/conditional-function-score-query/21555>\
**Category:** Elasticsearch\
**Created:** [January 9, 2015, 10:38am UTC](https://discuss.elastic.co/t/conditional-function-score-query/21555 "2015-01-09T10:38:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Wee](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@Jason\_Wee](https://discuss.elastic.co/u/Jason_Wee)\
**Post date:** [January 9, 2015, 10:38am UTC](https://discuss.elastic.co/t/conditional-function-score-query/21555/1 "2015-01-09T10:38:35Z")

</div>

Hi,

I have build a query using java FunctionScoreQueryBuilder  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/query-dsl-function-score-query.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/query-dsl-function-score-query.html)  
and was wondering if it possible to create a conditional scoring to the  
field? For example if the field exists and count = 1, apply factionFunction  
of 1.0f . And if the field existsa nd count = 2, then apply factionFunction  
of 2.0f , etc etc.

Is this possible?

Thanks.

Jason

--  
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/62f3b076-005c-4a8e-a447-a66015db633a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/62f3b076-005c-4a8e-a447-a66015db633a%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [January 9, 2015, 4:14pm UTC](https://discuss.elastic.co/t/conditional-function-score-query/21555/2 "2015-01-09T16:14:45Z")

</div>

You can check out  
[GitHub - jprante/elasticsearch-functionscore-conditionalboost: Boost documents in Elasticsearch when they match dynamic conditions](https://github.com/jprante/elasticsearch-functionscore-conditionalboost) for  
an example of how this can be done with a Java plugin.

Jörg

On Fri, Jan 9, 2015 at 11:38 AM, Jason Wee [peichieh@gmail.com](mailto:peichieh@gmail.com) wrote:

> Hi,
> 
> I have build a query using java FunctionScoreQueryBuilder  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/query-dsl-function-score-query.html)  
> and was wondering if it possible to create a conditional scoring to the  
> field? For example if the field exists and count = 1, apply factionFunction  
> of 1.0f . And if the field existsa nd count = 2, then apply factionFunction  
> of 2.0f , etc etc.
> 
> Is this possible?
> 
> Thanks.
> 
> Jason
> 
> --  
> 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/62f3b076-005c-4a8e-a447-a66015db633a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/62f3b076-005c-4a8e-a447-a66015db633a%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/62f3b076-005c-4a8e-a447-a66015db633a%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/62f3b076-005c-4a8e-a447-a66015db633a%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/CAKdsXoFm24Wy1FEtYGBp%3D46Psx2BOcs-EELF7zZEQ3hsRqE0dw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoFm24Wy1FEtYGBp%3D46Psx2BOcs-EELF7zZEQ3hsRqE0dw%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Jason\_Wee](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@Jason\_Wee](https://discuss.elastic.co/u/Jason_Wee)\
**Post date:** [January 12, 2015, 11:02am UTC](https://discuss.elastic.co/t/conditional-function-score-query/21555/3 "2015-01-12T11:02:33Z")

</div>

Thanks Jörg although we are using es version 0.90.7 and the project using  
es version 1.2.1. Not sure if it support.

Anyway, I achieve similar behaviour by using range filter (from 0 to less  
than or equal to 1, then boost 10f for example.) and passed that  
to FunctionScoreQueryBuilder.

Jason

On Saturday, January 10, 2015 at 12:14:58 AM UTC+8, Jörg Prante wrote:

> You can check out  
> [GitHub - jprante/elasticsearch-functionscore-conditionalboost: Boost documents in Elasticsearch when they match dynamic conditions](https://github.com/jprante/elasticsearch-functionscore-conditionalboost)  
> for an example of how this can be done with a Java plugin.
> 
> Jörg
> 
> On Fri, Jan 9, 2015 at 11:38 AM, Jason Wee \<[peic...@gmail.com](mailto:peic...@gmail.com)  
> \<javascript:\>\> wrote:
> 
> > Hi,
> > 
> > I have build a query using java FunctionScoreQueryBuilder  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/query-dsl-function-score-query.html)  
> > and was wondering if it possible to create a conditional scoring to the  
> > field? For example if the field exists and count = 1, apply factionFunction  
> > of 1.0f . And if the field existsa nd count = 2, then apply factionFunction  
> > of 2.0f , etc etc.
> > 
> > Is this possible?
> > 
> > Thanks.
> > 
> > Jason
> > 
> > --  
> > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/elasticsearch/62f3b076-005c-4a8e-a447-a66015db633a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/62f3b076-005c-4a8e-a447-a66015db633a%40googlegroups.com)  
> > [https://groups.google.com/d/msgid/elasticsearch/62f3b076-005c-4a8e-a447-a66015db633a%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/62f3b076-005c-4a8e-a447-a66015db633a%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/e10f7bfb-4c73-4c76-ba94-8f2dc87aa245%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e10f7bfb-4c73-4c76-ba94-8f2dc87aa245%40googlegroups.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:39am UTC](https://discuss.elastic.co/t/conditional-function-score-query/21555/4 "2017-07-06T00:39:35Z")

</div>


