# Problem with boosting depending on date

**URL:** <https://discuss.elastic.co/t/problem-with-boosting-depending-on-date/11049>\
**Category:** Elasticsearch\
**Created:** [March 7, 2013, 9:00am UTC](https://discuss.elastic.co/t/problem-with-boosting-depending-on-date/11049 "2013-03-07T09:00:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Calle\_Arnesten](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/calle_arnesten/32/1878_2.png) [@Calle\_Arnesten](https://discuss.elastic.co/u/Calle_Arnesten)\
**Post date:** [March 7, 2013, 9:00am UTC](https://discuss.elastic.co/t/problem-with-boosting-depending-on-date/11049/1 "2013-03-07T09:00:03Z")

</div>

Hi,

I'm new to ElasticSearch and I'm struggling to get a query with boosting  
depending on date to work as I want it.

In my index I have task documents that can look like this:

{  
name: 'Project X',  
date: '2012-01-01',  
taskType: 1  
}

{  
name: 'Project Y',  
date: '2013-01-01',  
taskType: 2  
}

{  
name: 'Project Z',  
date: '2013-03-07',  
taskType: 2  
}

Now I'm trying to do a query that gives higher boosting to newer tasks BUT  
only for taskType=[2,3]. For taskType=[1,4] I want to have the same  
boosting as the highest date boosting as the other group, meaning that  
tasks with taskType=[1,4] have the same boost factor as recently created  
tasks with taskType=[2,3]. So if I search on "project" with the above data,  
"Project X" and "Project Z" should have got the same rank. "Project Y"  
should have a lower rank.

Here is my attempt to accomplish this:

{  
query: {  
bool: {  
must: {  
query\_string: {  
query: 'project',  
fields: ['task.name']  
}  
},  
minimum\_number\_should\_match: 0,  
should: [  
{  
terms: {  
taskType: [1,4]  
boost: 10,  
minimum\_match: 1  
}  
},  
{  
bool: {  
must: {  
terms: {  
taskType: [2,3],  
minimum\_match: 1  
}  
},  
should: [  
range: {  
boost: 10,  
gt: '2013-02-07'  
},  
range: {  
boost: 5,  
lte: '2013-02-07',  
gt: '2013-01-07'  
},  
range: {  
boost: 3,  
lte: '2013-01-07',  
gt: '2012-12-07'  
},  
range: {  
boost: 1,  
lte: '2012-12-07'  
}  
]  
}  
}  
]  
}  
}  
}

Please note that the dates above is determined from today's date. In the  
example above today = 2013-03-07. Also, the example is greatly simplified  
from the real usage, what taskTypes that should be date boosted are  
dynamically determined.

When using the query above I get tasks with taskType=[2,3] that are created  
within the nearest month to be ranked HIGHER than tasks with [1,4] when  
they have the same name. I want them to be ranked the same. What am I doing  
wrong?

As I said, I'm new to ElasticSearch so if there is a more efficient,  
alternative syntax, please let me know.

/Calle

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Calle\_Arnesten](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/calle_arnesten/32/1878_2.png) [@Calle\_Arnesten](https://discuss.elastic.co/u/Calle_Arnesten)\
**Post date:** [March 11, 2013, 1:28pm UTC](https://discuss.elastic.co/t/problem-with-boosting-depending-on-date/11049/2 "2013-03-11T13:28:29Z")

</div>

Let me know if you need more information.

Any comments are appreciated.

/Calle

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 11, 2013, 3:14pm UTC](https://discuss.elastic.co/t/problem-with-boosting-depending-on-date/11049/3 "2013-03-11T15:14:40Z")

</div>

You can achieve some of what you are seeking with the Custom Filter Score  
Query

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

Your filter will be on the data and task type, and the boost will be  
generated by a script. There are limitations however. Your scripts cannot  
determine what the boost level from another script is, so your values have  
to be static. Also, the performance of your query will be affected since a  
script would need to be executed.

Cheers,

Ivan

On Mon, Mar 11, 2013 at 6:28 AM, Calle Arnesten \<[calle.arnesten@codekick.com](mailto:calle.arnesten@codekick.com)

> wrote:

> Let me know if you need more information.
> 
> Any comments are appreciated.
> 
> /Calle
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Calle\_Arnesten](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/calle_arnesten/32/1878_2.png) [@Calle\_Arnesten](https://discuss.elastic.co/u/Calle_Arnesten)\
**Post date:** [March 12, 2013, 9:37am UTC](https://discuss.elastic.co/t/problem-with-boosting-depending-on-date/11049/4 "2013-03-12T09:37:19Z")

</div>

That's exactly the pointer I needed. Now I got it working the way I wanted.  
Thanks a lot for your help!

/Calle

Den måndagen den 11:e mars 2013 kl. 16:14:40 UTC+1 skrev Ivan Brusic:

> You can achieve some of what you are seeking with the Custom Filter Score  
> Query
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/custom-filters-score-query.html)
> 
> Your filter will be on the data and task type, and the boost will be  
> generated by a script. There are limitations however. Your scripts cannot  
> determine what the boost level from another script is, so your values have  
> to be static. Also, the performance of your query will be affected since a  
> script would need to be executed.
> 
> Cheers,
> 
> Ivan
> 
> On Mon, Mar 11, 2013 at 6:28 AM, Calle Arnesten \<[calle.a...@codekick.com](mailto:calle.a...@codekick.com)\<javascript:\>
> 
> > wrote:
> 
> > Let me know if you need more information.
> > 
> > Any comments are appreciated.
> > 
> > /Calle
> > 
> > --  
> > 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:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:47am UTC](https://discuss.elastic.co/t/problem-with-boosting-depending-on-date/11049/5 "2017-07-06T02:47:02Z")

</div>


