0
votes

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?

1

1 Answers

1
votes

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"));