# Boost field A based on range field B

**URL:** https://discuss.elastic.co/t/boost-field-a-based-on-range-field-b/153166
**Category:** Elasticsearch
**Created:** [October 19, 2018, 11:14am UTC](https://discuss.elastic.co/t/boost-field-a-based-on-range-field-b/153166 "2018-10-19T11:14:35Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Maarten\_Koopmans](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maarten_koopmans/32/36710_2.png) [@Maarten\_Koopmans](https://discuss.elastic.co/u/Maarten_Koopmans)
#### Post date: [October 19, 2018, 11:14am UTC](https://discuss.elastic.co/t/boost-field-a-based-on-range-field-b/153166/1 "2018-10-19T11:14:35Z")

</div>

Hi,

I have trimmed down my issue to this minimal use case. Say I have a document type fruits:

{  
"fruit":"apple"  
"flavourScore":1.4  
"pricePerKg": 9  
}

What I would like to be able to do (but can't seem to figure out) is boost the flavourScore if the pricePerKg is in a a range, say 8-10/kg, but not otherwise. I'm pretty sure this is possible - the abstract question would be:

Boost field A if the value of field B falls within a numeric range.

Any help (especially a sample query DSL) or insight greatly appreciated!

Thanks,

Maarten

---

<div class="post-metadata">

### Author: ![Maarten\_Koopmans](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maarten_koopmans/32/36710_2.png) [@Maarten\_Koopmans](https://discuss.elastic.co/u/Maarten_Koopmans)
#### Post date: [October 22, 2018, 6:02am UTC](https://discuss.elastic.co/t/boost-field-a-based-on-range-field-b/153166/2 "2018-10-22T06:02:24Z")

</div>

Hi,

I'd expected somebody out there would know the trick..... Is this impossible with ElasticSearch or a case of RTFM? If the latter, a pointer would be appreciated!

Warm regards,

Maarten Koopmans

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [October 22, 2018, 6:58am UTC](https://discuss.elastic.co/t/boost-field-a-based-on-range-field-b/153166/3 "2018-10-22T06:58:01Z")

</div>

I wonder if function score could help you here?

---

<div class="post-metadata">

### Author: ![Maarten\_Koopmans](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maarten_koopmans/32/36710_2.png) [@Maarten\_Koopmans](https://discuss.elastic.co/u/Maarten_Koopmans)
#### Post date: [October 22, 2018, 11:25am UTC](https://discuss.elastic.co/t/boost-field-a-based-on-range-field-b/153166/5 "2018-10-22T11:25:10Z")

</div>

I briefly looked at that, but anything else than the pseudo-code:

if X in range (a,b) then boost Y

seems overly complicated. I can live with if it's complicated, but then I would like to use this thread to create an abstraction using the more complicated building blocks to allow those coming after me with this need to write it more like the ^^

---

<div class="post-metadata">

### Author: ![Maarten\_Koopmans](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maarten_koopmans/32/36710_2.png) [@Maarten\_Koopmans](https://discuss.elastic.co/u/Maarten_Koopmans)
#### Post date: [October 22, 2018, 1:40pm UTC](https://discuss.elastic.co/t/boost-field-a-based-on-range-field-b/153166/6 "2018-10-22T13:40:06Z")

</div>

I don't see how I can do this in _one_ query.

I can see the boost on say 8-10e/kg if I combine that range as filter and a boost on the flavourFactor if the field exists (if that is possible. But I think I would need a second query to get all the results below 8e

---

<div class="post-metadata">

### Author: ![Maarten\_Koopmans](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maarten_koopmans/32/36710_2.png) [@Maarten\_Koopmans](https://discuss.elastic.co/u/Maarten_Koopmans)
#### Post date: [October 22, 2018, 1:43pm UTC](https://discuss.elastic.co/t/boost-field-a-based-on-range-field-b/153166/7 "2018-10-22T13:43:02Z")

</div>

Maybe I could use a script score function, I can see how I could partition the data in painless as scripting language. But I'm not sure how can I enable a boots in painless other than changing the documents score (which would be primitive, like multiplying by X).

Is there a "boost" in painless?

---

<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: [November 19, 2018, 1:43pm UTC](https://discuss.elastic.co/t/boost-field-a-based-on-range-field-b/153166/8 "2018-11-19T13:43:03Z")

</div>

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