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.