# Approach for incorporating recency in search

**URL:** <https://discuss.elastic.co/t/approach-for-incorporating-recency-in-search/185209>\
**Category:** Elasticsearch\
**Created:** [June 11, 2019, 2:02pm UTC](https://discuss.elastic.co/t/approach-for-incorporating-recency-in-search/185209 "2019-06-11T14:02:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikita.jain](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nikita.jain](https://discuss.elastic.co/u/nikita.jain)\
**Post date:** [June 11, 2019, 2:02pm UTC](https://discuss.elastic.co/t/approach-for-incorporating-recency-in-search/185209/1 "2019-06-11T14:02:18Z")

</div>

Hi,

I'm trying to improve the relevance of search results using user's recent activity, in order to personalize the search experience. I have the data of the user's recent activity, in addition to an exhaustive database of all the possible search items. I want to boost the relevant matches from recent activity with a higher factor than other matches.

Following are the approaches I could come up with:

1. Performing [index boost](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-index-boost.html) on the user based index of recent data, and giving it a higher boost factor than rest of the indices.

2. Making a query to Elastic Search using AND logic.

Eg:  
"should": [  
{  
"bool": {  
"must": [  
{  
"multi\_match": {  
"query": "1",  
"fields": [  
"field1$^1000"  
],  
"type": "phrase"  
}  
},  
{  
"multi\_match": {  
"query": "test",  
"fields": [  
"field2$^100",  
"field3$^10",  
],  
"type": "phrase"  
}  
}  
]  
}  
},  
{  
"multi\_match": {  
"query": "test",  
"fields": [  
"field2$^100",  
"field3$^10",  
,  
"type": "phrase"  
}  
}  
]

In this, the results with value of field1=1 and having a valid match for term "test" across field2 and/or field3 will be boosted with a higher factor than the conventional match.

1. [Boosting query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html) with a negative boost to demote certain results. But this somehow [fails to apply the negative boost factor](https://discuss.elastic.co/t/issue-in-boosting-query-assigning-negative-boost/185181).

2. [Designing a script](https://www.elastic.co/guide/en/elasticsearch/reference/7.1/modules-scripting-engine.html) to assign higher score to items which are recent, and using it as a plugin in the desired query.

The first two approaches are posing some serious performance issues, and the third one is not working. The best available option right now is the last one.

I want to know if there's any other better approach which can be used here.

Thank you!

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [June 12, 2019, 1:09am UTC](https://discuss.elastic.co/t/approach-for-incorporating-recency-in-search/185209/2 "2019-06-12T01:09:47Z")

</div>

Hi,

Maybe you can take a look to this plugin:

> **[We’re Bringing Learning to Rank to Elasticsearch](https://opensourceconnections.com/blog/2017/02/14/elasticsearch-learning-to-rank/)**
>
> Announcing the Elasticsearch Learning to Rank Plugin: Bringing machine learning into Elasticsearch to improve search relevance.

---

<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 10, 2019, 1:09am UTC](https://discuss.elastic.co/t/approach-for-incorporating-recency-in-search/185209/3 "2019-07-10T01:09:47Z")

</div>

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