0

I have data like

 id,          title
  1. 'Deploying SQL Server Databases from Test to Live'
  2. 'Deploying SQL Server Databases for clients'
  3. 'Merge SQL Server databases'
  4. 'SQL Server : gather data from different databases'
  5. .......
  6. ....... more then millions of records.

my search query be like

from elasticsearch import Elasticsearch
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
bd={
    'query':{
        'match': {
            'title': "Deploying SQL Server Databases from Test to Live"
            }
        },
    'sort': {
        '_score': {
            'order': 'desc'
            }
        }
    }

res = es.search(index='abc-index', body=bd)

My search result :

{
  "took": 1297,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 10000,
      "relation": "gte"
    },
    "max_score": 38.9089,
    "hits": [
      {
        "_index": "abc-index",
        "_type": "_doc",
        "_id": "1",
        "_score": 38.9089,  #normalized this value to some range [a,b]
        "_source": {
          "id": 1,
          "title": "Deploying SQL Server Databases from Test to Live"
        }
      },
      {
        "_index": "abc-index",
        "_type": "_doc",
        "_id": "2",
        "_score": 25.427029, #normalized this value to some range [a,b]
        "_source": {
          "id": 2,
          "title": "Deploying SQL Server Databases for clients"
        }
      },
      {
        "_index": "abc-index",
        "_type": "_doc",
        "_id": "3",
        "_score": 19.293251, #normalized this value to some range [a,b]
        "_source": {
          "id": 3,
          "title": "Merge SQL Server databases"
        }
      },
      {
        "_index": "abc-index",
        "_type": "_doc",
        "_id": "4",
        "_score": 18.969624, #normalized this value to some range [a,b]
        "_source": {
          "id": 4,
          "title": "SQL Server : gather data from different databases"
        }
      }
       ..........  # 10,000 query result
    ]
  }
}

I want _score value normalized in some range [a,b] for example [0,2].Can anyone please help me how to do that.

Akash Kumar
  • 182
  • 2
  • 12
  • iterate through results - it's application logic - find min and max score and multiply – Michal Miky Jankovský Jun 15 '20 at 15:37
  • What I added is just a part of data in total I have millions of records and and query result restrict to only 10000 result So I don't know the total range.Iteration through out the whole response is very costly. – Akash Kumar Jun 15 '20 at 17:01

0 Answers0