Match Score With Spring data elastic search in Spring Boot for a Query

Match Score With Spring data elastic search in Spring Boot for a Query

Hi everyone, I am going to share the scoring and percentage from the Elastic search query to order results and show them to the user on your web application interface.

Previously, I was using an elastic search Rest Client template to have a search query, but that way I had to extract the score, and list of data with mapping to the required format. The configuration is a little more complex than using Spring Data Elasticsearch directly. But after looking for a solution to fix some other issues I have, I got the solution for getting a score directly from spring data elasticsearch with a little modification.

[su_note color=”#deb5a2″]Also Read | Add Amazon Comprehend to Spring Boot App[/su_note]

Let me share.

I have done with pagination, but you can do it normally too by using stream with a list instead. let me know if you want in the comments below, I will add.

Steps to get Match Score Elasticsearch

  1. We create a normal Query like a match query
  2. call the bookpage method with a query and pageable parameters
  3. Create a search query with the required options
  4. Call the elastic search template query method to modify and extract the response. it is the main point where you get the hit score and total hits.
  5. Call the additional bookDOFromMap method to get a score and append it to DTO.

6. Now you have the score calculated from the Hit score of each record vs all records.

You can modify the query or scoring logic; by using a function score query with a scoring function for your needs.

I hope it will help, you.

[su_note color=”#deb5a2″]Also Read | Add AWS Transcribe to Spring Boot APP[/su_note]

Balvinder Singh
Balvinder Singh

Founder And Editor at Loves to write about technology, gaming, business, tips and tricks. Working as a Senior Software Engineer in Infosys India. Exploring different blockchains as well.

Articles: 362

Leave a Reply

Your email address will not be published. Required fields are marked *