mbuhot / eskotlin

Elasticsearch Query DSL for Kotlin
MIT License
136 stars 28 forks source link

field_value_factor #36

Closed champloo11 closed 4 years ago

champloo11 commented 5 years ago

Elasticsearch allows you to boost/modify the score of documents using function_score and field_value_factor based on a property that exists on the documents. This is commonly used to implement a popularity system (likes, pageviews, etc...) to improve the perceived relevancy of results.

For example:

GET /_search
{
    "query": {
        "function_score": {
            "field_value_factor": {
                "field": "likes",
                "factor": 1.2,
                "modifier": "sqrt",
                "missing": 1
            }
        }
    }
}

Also discussed here: https://nocf-www.elastic.co/guide/en/elasticsearch/guide/master/boosting-by-popularity.html

Question #1: does ESKotlin support field_value_factor? A cursory search appears to show "no".

Question #2: If ESKotlin does not support field_value_factor how difficult would it be to add?

mbuhot commented 5 years ago

@champloo11 any functionality exposed through the java API can usually be added to es_kotlin quite easily.

Please send a PR adding this to the function score query builder 👍

champloo11 commented 4 years ago

A little bit late since our project had to go with the regular ES QueryBuilders, but here's the implementation of a top-level field_value_factor.

https://github.com/mbuhot/eskotlin/pull/38/files

champloo11 commented 4 years ago

@mbuhot Per the merge yesterday, this issue can be resolved.

mbuhot commented 4 years ago

Thanks again @champloo11 👍