I'd like to write a custom Elastic Search scorer that takes all terms from the document in index, all terms from the query and based on some custom logic calculates the score.
After some research, it seems that the most straight-forward way to implement a custom scorer in Elastic Search in Java is to use its "native scripting" functionality (i.e. implementing AbstractDoubleSearchScript). The problem I have is that I can't find a way to access the original query object in such a script. I can only access the matching document and its fields. Is there some way to get access to the query object that was used for the search?
Alternatively, what is the best way to run custom Java code per result and score the match using my own (complex) algorithm that needs to know the complete term list for both the query and the document?
About ElasticsearchElasticsearch is also an open-source search engine built on top of Apache Lucene, as the rest of the ELK Stack, including Logstash and Kibana.
Elasticsearch is built on top of Lucene. Elasticsearch converts Lucene into a distributed system/search engine for scaling horizontally. Elasticsearch also provides other features like thread-pool, queues, node/cluster monitoring API, data monitoring API, Cluster management, etc.
The default scoring algorithm used by Elasticsearch is BM25. There are three main factors that determine a document's score: Term frequency (TF) — The more times that a search term appears in the field we are searching in a document, the more relevant that document is.
Implement a custom Query class and wrap the actual query (for example a boolean query) as its sub query. In the Query class you have api to implement a custom scorer where you can have access to both the query and the current document which you are scoring. To fine grain control the score, implement a custom similarity class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With