# Sum score in multi match

**URL:** <https://discuss.elastic.co/t/sum-score-in-multi-match/122547>\
**Category:** Elasticsearch\
**Created:** [March 5, 2018, 3:17pm UTC](https://discuss.elastic.co/t/sum-score-in-multi-match/122547 "2018-03-05T15:17:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![a.korshunov](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@a.korshunov](https://discuss.elastic.co/u/a.korshunov)\
**Post date:** [March 5, 2018, 3:17pm UTC](https://discuss.elastic.co/t/sum-score-in-multi-match/122547/1 "2018-03-05T15:17:14Z")

</div>

Hi, guys.

I want to sum score in multi match query with cross\_field type and set tie\_breaker to 1.0. I test two versions of Elasticsearch: 5.4.0 and 6.2.1. Version 5.4.0 works as expected, but in 6.2.1 occurs maximum instead of summary, as I wanted.

Example code:

> ```
> PUT test
> {
> "settings": {
> "number_of_replicas": 0,
> "number_of_shards": 1
> },
> "mappings": {
> "type1": {
> "properties": {
> "title": {
> "type": "text"
> },
> "description": {
> "type": "text"
> }
> }
> }
> }
> }
> 
> ```

> ```
> POST test/type1
> {
> "title": "Great Gatsby",
> "description": "Great Gatsby is the book about ..."
> }
>  
> GET test/type1/_search
> {
> "explain": true, 
> "query": {
> "multi_match": {
> "query": " Great Gatsby",
> "type": "cross_fields", 
> "tie_breaker": 1, 
> "fields": ["title^0.9", "description^0.4"]
> }
> }
> }
> 
> ```

Result in 5.4.0:

> ```
> {
> "took": 3,
> "timed_out": false,
> "_shards": {
> "total": 1,
> "successful": 1,
> "failed": 0
> },
> "hits": {
> "total": 1,
> "max_score": 0.67854714,
> "hits": [
> {
> "_shard": "[test][0]",
> "_node": "6I5w97MhSqiV-kkuiKq3Ig",
> "_index": "test",
> "_type": "type1",
> "_id": "AWH2m1UNIkD_TjFR4SoN",
> "_score": 0.67854714,
> "_source": {
> "title": "Great Gatsby",
> "description": "Great Gatsby is the book about ..."
> },
> "_explanation": {
> "value": 0.67854714,
> "description": "sum of:",
> "details": [
> {
> "value": 0.33927357,
> "description": " **sum of** :",
> "details": [
> {
> "value": 0.10696911,
> "description": "weight(description:great in 0) [PerFieldSimilarity], result of:",
> "details": ...
> },
> {
> "value": 0.23230445,
> "description": "weight(title:great in 0) [PerFieldSimilarity], result of:",
> "details": ...
> }
> ]
> },
> {
> "value": 0.33927357,
> "description": " **sum of** :",
> "details": [
> {
> "value": 0.10696911,
> "description": "weight(description:gatsby in 0) [PerFieldSimilarity], result of:",
> "details": ...
> },
> {
> "value": 0.23230445,
> "description": "weight(title:gatsby in 0) [PerFieldSimilarity], result of:",
> "details": ...
> ]
> }
> ]
> }
> ]
> }
> }
> ]
> }
> }
> 
> ```

Result in 6.2.1:

> ```
> {
> "took": 0,
> "timed_out": false,
> "_shards": {
> "total": 1,
> "successful": 1,
> "skipped": 0,
> "failed": 0
> },
> "hits": {
> "total": 1,
> "max_score": 0.51782775,
> "hits": [
> {
> "_shard": "[test][0]",
> "_node": "fUje_eDeTp6kXL83BFQM_Q",
> "_index": "test",
> "_type": "type1",
> "_id": "LF6d9mEBXfZ7hY5VVfJU",
> "_score": 0.51782775,
> "_source": {
> "title": "Great Gatsby",
> "description": "Great Gatsby is the book about ..."
> },
> "_explanation": {
> "value": 0.51782775,
> "description": "sum of:",
> "details": [
> {
> "value": 0.25891387,
> "description": " **max of** :",
> "details": [
> {
> "value": 0.25891387,
> "description": "weight(title:great in 0) [PerFieldSimilarity], result of:",
> "details": [
> {
> "value": 0.25891387,
> "description": "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
> "details": ...
> }
> ]
> },
> {
> "value": 0.11507284,
> "description": "weight(description:great in 0) [PerFieldSimilarity], result of:",
> "details": ...
> }
> ]
> },
> {
> "value": 0.25891387,
> "description": " **max of** :",
> "details": [
> {
> "value": 0.25891387,
> "description": "weight(title:gatsby in 0) [PerFieldSimilarity], result of:",
> "details": ...
> },
> {
> "value": 0.11507284,
> "description": "weight(description:gatsby in 0) [PerFieldSimilarity], result of:",
> "details": ...
> }
> ]
> }
> ]
> }
> }
> ]
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![a.korshunov](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@a.korshunov](https://discuss.elastic.co/u/a.korshunov)\
**Post date:** [March 6, 2018, 7:56am UTC](https://discuss.elastic.co/t/sum-score-in-multi-match/122547/2 "2018-03-06T07:56:42Z")

</div>

I figured out what was going on. I found changes in the source code in MultiMatchQuery.java. The commit 21a57c14945fb0b82d2b78a2c89e0d92bbc086a0 says:

> Always use **DisjunctionMaxQuery** to build cross fields disjunction (#25115)
> 
> This commit modifies query\_string, simple\_query\_string and multi\_match queries to always use a DisjunctionMaxQuery when a disjunction over multiple fields is built. The tiebreaker is set to 1 in order to behave like the boolean query in terms of scoring.  
> The removal of the coord factor in Lucene 7 made this change mandatory to correctly handle minimum\_should\_match.
> 
> Closes #23966

But the documentation says:  
when tie\_breaker = 1.0 then " **Add** together the scores for (eg) first\_name:will and last\_name:will"

In fact there is a maximum. It is an error in the documentation?

To sum score foreach field the query should be like this:  
GET test/type1/\_search

> ```
> {
> "explain": true,
> "query": {
> "bool": {
> "must": [
> {
> "multi_match": {
> "type": "most_fields",
> "query": "Great",
> "fields": [
> "title^0.9",
> "description^0.4"
> ]
> }
> },
> {
> "multi_match": {
> "type": "most_fields",
> "query": "Gatsby",
> "fields": [
> "title^0.9",
> "description^0.4"
> ]
> }
> }
> ]
> }
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![xabbu42](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xabbu42/32/44817_2.png) [@xabbu42](https://discuss.elastic.co/u/xabbu42)\
**Post date:** [March 7, 2018, 11:15pm UTC](https://discuss.elastic.co/t/sum-score-in-multi-match/122547/3 "2018-03-07T23:15:14Z")

</div>

I dont think your solution is equivalent to an elasticsearch 5 cross\_fields multi\_match query with tie\_breaker set to 1. You are missing the blended idf scores of cross\_fields. Anyway, at least the documentation should be fixed if the new behavior is intentional.

I opened an issue at [https://github.com/elastic/elasticsearch/issues/28933](https://github.com/elastic/elasticsearch/issues/28933).

---

<div class="post-metadata">

**Author:** ![a.korshunov](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@a.korshunov](https://discuss.elastic.co/u/a.korshunov)\
**Post date:** [March 8, 2018, 10:17am UTC](https://discuss.elastic.co/t/sum-score-in-multi-match/122547/4 "2018-03-08T10:17:36Z")

</div>

Thank you!

---

<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:** [April 5, 2018, 10:17am UTC](https://discuss.elastic.co/t/sum-score-in-multi-match/122547/5 "2018-04-05T10:17:42Z")

</div>

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