0

I am currently boosting on url, title, and description as follows:

QueryBuilder qb = QueryBuilders.multiMatchQuery(term,"title", "description","url").field("title", 1.75f).field("url", 1.55f).field("description", 1.35f);

I would like to further add boosting to documents created more recently (I have a postDate field mapped as date).

I found this SO Post pointing to a legacy ES Doc which refers to gaussian decay. However, I cannot seem to find this in the current Java Api doc.

How would I add a boost to my QueryBuilder for more recently created (postDate) documents?

Community
  • 1
  • 1
Chris
  • 18,075
  • 15
  • 59
  • 77

1 Answers1

1

You should have a look at the function score query: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html

The following code gives a hint to what you could use:

QueryBuilder qb = QueryBuilders.multiMatchQuery(term,"title", "description","url").field("title", 1.75f).field("url", 1.55f).field("description", 1.35f);
FunctionScoreQueryBuilder builder = QueryBuilders.functionScoreQuery(qb);
builder.add(ScoreFunctionBuilders.exponentialDecayFunction("postDate","14d"));
Jettro Coenradie
  • 4,735
  • 23
  • 31
  • Thank you! Quick question based on the link above, does the "14d" mean everything inside of 14 days gets a boost? Where day 1 gets a higher boost than day 13? And everything after 14 decays exponentially (backend of bell curve)? – Chris Jan 22 '15 at 15:29
  • Hm, the way I understood things get less boost up to 14 days and after 14 days there is no boost anymore. – Jettro Coenradie Jan 22 '15 at 15:33