How to modify scores of documents based on partial and exact match

Hello I am finding a solution to achieve a scenario where an index having suppose 10 records each record having last name, first name and phone number etc fields and I want to do partial match and exact match for these fields and also modify the scores of the documents according to how much they match with the given value of these fields. For example, what ever value we give for firstname the documents having partial matching will have less score, documents having exact matching will have more score and two records having exact match will have same score. How can I achieve that ?
Right Now I figured out this process

  1. In order to do partial match I am going ahead I am using query string. however, tried with other queries as well such as wildcard as well but I think it does not work with text/string values
  2. To modify the score of each record according to the query I considered 2 solutions
  3. function_score function
  4. script_score function
  5. I am working with script_score function now
  6. Inside script_score I am using randomScore() function with values passed as 100
  7. To calculate percentage for every search result we get a max score value
  8. I will be using this formula to calculate the percentages for each document
    percenatge = (score of every record/max score)*100
    After all this I am not able to achieve desired scores for each document.

I am using this query for achieving above functionality

  GET customers-rcn/_search
  "query": {
    "script_score": {
      "query": {
        "query_string": {
            "query": "*mol*",
              "fields": ["lastName^1.0"]
      "script" : {
    "source" : "randomScore(100)"

Please can someone tell me the solution?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.