I\'m currently implementing elasticsearch in my Symfony2 application via the FOQElasticaBundle and so far it\'s been working great based on boosts applied to various fields
A full elasticsearch 5 example based on function_score. See this blogpost and function_score docs for more info.
Allows for boosting more recent entries based on multiple date ranges, with varying strengths, on a gaussian curve without "hard cutoffs".
{
"query": {
"function_score": {
"score_mode": "sum", // All functions outputs get summed
"boost_mode": "multiply", // The documents relevance is multiplied with the sum
"functions": [
{
// The relevancy of old posts is multiplied by at least one.
// Remove if you want to exclude old posts
"weight": 1
},
{
// Published this month get a big boost
"weight": 5,
"gauss": {
"date": { // <- Change to your date field name
"origin": "2017-04-07", // Change to current date
"scale": "31d",
"decay": 0.5
}
}
},
{
// Published this year get a boost
"weight": 2,
"gauss": {
"date": { // <- Change to your date field name
"origin": "2017-04-07", // Change to current date
"scale": "356d",
"decay": 0.5
}
}
}
],
"query": {
// The rest of your search here, change to something relevant
"match": { "title": "< your search string >" }
}
}
}
}