# Score is same for single value match vs multiple match for an array field using terms query

**URL:** <https://discuss.elastic.co/t/score-is-same-for-single-value-match-vs-multiple-match-for-an-array-field-using-terms-query/314976>\
**Category:** Elasticsearch\
**Created:** [September 22, 2022, 9:38pm UTC](https://discuss.elastic.co/t/score-is-same-for-single-value-match-vs-multiple-match-for-an-array-field-using-terms-query/314976 "2022-09-22T21:38:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Divit\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/divit_sharma/32/32348_2.png) [@Divit\_Sharma](https://discuss.elastic.co/u/Divit_Sharma)\
**Post date:** [September 22, 2022, 9:38pm UTC](https://discuss.elastic.co/t/score-is-same-for-single-value-match-vs-multiple-match-for-an-array-field-using-terms-query/314976/1 "2022-09-22T21:38:52Z")

</div>

```auto
PUT dvt_test_long/_doc/1
{
  "items" : [1] 
}

PUT dvt_test_long/_doc/2
{
  "items" : [1, 2] 
}

PUT dvt_test_long/_doc/3
{
  "items" : [1, 2, 3] 
}

PUT dvt_test_long/_doc/4
{
  "items" : [1, 2, 3, 4] 
}

```

Query:

```auto
GET dvt_test_long/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "terms": {
            "items": [
              "3",
              "4"
            ]
          }
        }
      ]
    }
  }
}

```

Response:

```auto
{
  "took" : 917,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 2,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "dvt_test_long",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
          "items" : [
            1,
            2,
            3
          ]
        }
      },
      {
        "_index" : "dvt_test_long",
        "_type" : "_doc",
        "_id" : "4",
        "_score" : 1.0,
        "_source" : {
          "items" : [
            1,
            2,
            3,
            4
          ]
        }
      }
    ]
  }
}

```

As you can see, `[1, 2, 3] ` has same score as `[1, 2, 3, 4] ` where there were two matches `[3, 4]`.

Is it possible to score the documents more based on no. of values matched ?

I want `[1, 2, 3, 4] ` to score higher.

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [September 22, 2022, 11:24pm UTC](https://discuss.elastic.co/t/score-is-same-for-single-value-match-vs-multiple-match-for-an-array-field-using-terms-query/314976/2 "2022-09-22T23:24:41Z")

</div>

Hi @Divit_Sharma

Try add match inside should clasule.

```auto
 {
          "match": {
            "items": "3"
          }
        },
        {
          "match": {
            "items": "4"
          }
        }

```

---

<div class="post-metadata">

**Author:** ![Divit\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/divit_sharma/32/32348_2.png) [@Divit\_Sharma](https://discuss.elastic.co/u/Divit_Sharma)\
**Post date:** [September 22, 2022, 11:34pm UTC](https://discuss.elastic.co/t/score-is-same-for-single-value-match-vs-multiple-match-for-an-array-field-using-terms-query/314976/3 "2022-09-22T23:34:04Z")

</div>

Two items to search was just an example.

Array to be searched can be of any no. of values. This example would make me use multiple match blocks based on the no. of values in array. So not what I am looking for.

Another solution was to use:

```auto
{ "match": { "items": "3 4" }

```

But this fails for **long** values.

---

<div class="post-metadata">

**Author:** ![Divit\_Sharma](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/divit_sharma/32/32348_2.png) [@Divit\_Sharma](https://discuss.elastic.co/u/Divit_Sharma)\
**Post date:** [September 23, 2022, 11:42am UTC](https://discuss.elastic.co/t/score-is-same-for-single-value-match-vs-multiple-match-for-an-array-field-using-terms-query/314976/4 "2022-09-23T11:42:48Z")

</div>

Okay this seems to work but I can't just pass the list will have to build the search string as value1 OR value2 OR value3 etc.

```auto
GET dvt_test_long/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "query": "items: (3 OR 4)"
          }
        }
      ]
    }
  }
} 

```

```auto
[
      {
        "_index" : "dvt_test_long",
        "_type" : "_doc",
        "_id" : "4",
        "_score" : 2.0,
        "_source" : {
          "items" : [
            1,
            2,
            3,
            4
          ]
        }
      },
      {
        "_index" : "dvt_test_long",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
          "items" : [
            1,
            2,
            3
          ]
        }
      }
    ]

```

---

<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 21, 2022, 11:43am UTC](https://discuss.elastic.co/t/score-is-same-for-single-value-match-vs-multiple-match-for-an-array-field-using-terms-query/314976/5 "2022-10-21T11:43:48Z")

</div>

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