# Es score from 0 to 1 when finding similar documents to existing one

**URL:** https://discuss.elastic.co/t/es-score-from-0-to-1-when-finding-similar-documents-to-existing-one/248919
**Category:** Elasticsearch
**Created:** [September 17, 2020, 7:03am UTC](https://discuss.elastic.co/t/es-score-from-0-to-1-when-finding-similar-documents-to-existing-one/248919 "2020-09-17T07:03:05Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![johanson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/johanson/32/46709_2.png) [@johanson](https://discuss.elastic.co/u/johanson)
#### Post date: [September 17, 2020, 7:03am UTC](https://discuss.elastic.co/t/es-score-from-0-to-1-when-finding-similar-documents-to-existing-one/248919/1 "2020-09-17T07:03:05Z")

</div>

Is it possible to calculate relative score from 0 to 1 when searching similar documents to existing one?  
Need to calculate relative score from 0 to 1 when searching similar documents to existing one. So existing one has score 1, and all other matching documents scores should be calculated according to this]. But existing document should be excluded from the search. Is it possible to do it on elasticsearch side, not just calculating score manually in a programming language like: `match_doc_score/search_doc_score`

Let's imagine we have index `person` with mapping:

```auto
{
  "properties": {
    "person_id": {
      "type": "keyword"
    },
    "fullname": {
      "type": "text"
    },
    "email": {
      "type": "keyword"
    },
    "phone": {
      "type": "keyword"
    },
    "country_of_birth": {
      "type": "keyword"
    }
  }
}

```

And I have 3 persons inside the index:  
Person 1:

```auto
{
  "person_id": 1,
  "fullname": "John Snow",
  "email": "john@gmail.com",
  "phone": "111-11-11",
  "country_of_birth": "Denmark"
}

```

Person 2:

```auto
{
  "person_id": 2,
  "fullname": "Snow John",
  "email": "john@gmail.com",
  "phone": "222-22-22",
  "country_of_birth": "Denmark"
}

```

Person 3:

```auto
{
  "person_id": 3,
  "fullname": "Peter Wislow",
  "email": "peter@gmail.com",
  "phone": "111-11-11",
  "country_of_birth": "Denmark"
}

```

We find persons that are similar to Person 1 by this query:

```auto
{
    "query": {
        "bool": {
            "should": [
                {
                    "match": {
                        "fullname": {
                            "query": "John Snow",
                            "boost": 6
                        }
                    }
                },
                {
                    "term": {
                        "email": {
                            "value": "john@gmail.com",
                            "boost": 5
                        }
                    }
                },
                {
                    "term": {
                        "phone": {
                            "value": "111-11-11",
                            "boost": 4
                        }
                    }
                },
                {
                    "term": {
                        "country_of_birth": {
                            "value": "Denmark",
                            "boost": 2
                        }
                    }
                }
            ],
            "must_not": [
                {
                    "term": {
                        "person_id": 123
                    }
                }
            ]
        }
    }
}

```

As you can see:

- person 1 and person 2 match by: fullname, email, country of birth.
- person 1 and person 3 match by: phone, country of birth.

Is it possible to have 0..1 scoring if we have a document with full match in the index(person 1)?

I know there is a [more\_like\_this](https://www.elastic.co/guide/en/elasticsearch/reference/7.9//query-dsl-mlt-query.html) query, but in real life search queries can be complicated so `more_like_this` is not a good option. Even elasticsearch documentation says that if you need more control over the query, then use boolean query combinations.

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [September 17, 2020, 10:30pm UTC](https://discuss.elastic.co/t/es-score-from-0-to-1-when-finding-similar-documents-to-existing-one/248919/2 "2020-09-17T22:30:24Z")

</div>

You might be able to do something with a custom scoring algorithm, that's well outside the scope with what I can help with myself.

Otherwise, nope you cannot.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 15, 2020, 10:30pm UTC](https://discuss.elastic.co/t/es-score-from-0-to-1-when-finding-similar-documents-to-existing-one/248919/3 "2020-10-15T22:30:47Z")

</div>

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