# Custom Score Based on Matches in String Array

**URL:** <https://discuss.elastic.co/t/custom-score-based-on-matches-in-string-array/138091>\
**Category:** Elasticsearch\
**Created:** [July 1, 2018, 6:06pm UTC](https://discuss.elastic.co/t/custom-score-based-on-matches-in-string-array/138091 "2018-07-01T18:06:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![UsAndFriends](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/usandfriends/32/32843_2.png) [@UsAndFriends](https://discuss.elastic.co/u/UsAndFriends)\
**Post date:** [July 1, 2018, 6:06pm UTC](https://discuss.elastic.co/t/custom-score-based-on-matches-in-string-array/138091/1 "2018-07-01T18:06:53Z")

</div>

We are trying to generate a document score based on the number of matches in an array of strings. For example, if there are 3 matched elements in the array, the score should increase by 3. Currently, we are using `function_score` query like so:

```auto
function_score: {
  ...
  functions: [{
    filter: {
      match: {
        expertises: "software hardware"
      }
    },
    weight: 1
  }]
}

```

The mapping for `expertises` property is like so:

```auto
expertises: {
  type: 'text',
  norms: {
    enabled: false
  },
  fields: {
    keyword: {
      type: 'keyword',
      ignore_above: 256
    }
  }
},

```

The issue is that this setup is giving a constant score no matter the amount of array items matched. Is it possible to compute a score based on number of items matched in the `expertises` array?

---

<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:** [July 29, 2018, 6:06pm UTC](https://discuss.elastic.co/t/custom-score-based-on-matches-in-string-array/138091/2 "2018-07-29T18:06:55Z")

</div>

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