Problem with boosting depending on date

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.
For more options, visit https://groups.google.com/groups/opt_out.

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.
For more options, visit https://groups.google.com/groups/opt_out.

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

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

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.
For more options, visit 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.
For more options, visit https://groups.google.com/groups/opt_out.

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

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<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 <javascript:>.
For more options, visit 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.
For more options, visit https://groups.google.com/groups/opt_out.