# Change the scoring function for array using best score for elements

**URL:** <https://discuss.elastic.co/t/change-the-scoring-function-for-array-using-best-score-for-elements/155807>\
**Category:** Elasticsearch\
**Created:** [November 8, 2018, 1:51am UTC](https://discuss.elastic.co/t/change-the-scoring-function-for-array-using-best-score-for-elements/155807 "2018-11-08T01:51:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jack1234](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jack1234](https://discuss.elastic.co/u/jack1234)\
**Post date:** [November 8, 2018, 1:51am UTC](https://discuss.elastic.co/t/change-the-scoring-function-for-array-using-best-score-for-elements/155807/1 "2018-11-08T01:51:51Z")

</div>

Consider I have a text field called 'question' with element  
`['one','one shift','one apple']`.  
Now say the query is `'one'` with the following search query:

```
query": {
    "match": {
        "question": {
            "query": 'one',
        }
    }
}

```

I want the scoring function to use the best score among the three matches `'one'`, `'one shift'`, `'one apple'` for the text field. How should I modify that? I am aware there is a [function score query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html), but I am not sure how to achieve that.

---

<div class="post-metadata">

**Author:** ![Jaspreet\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaspreet_singh/32/58296_2.png) [@Jaspreet\_Singh](https://discuss.elastic.co/u/Jaspreet_Singh)\
**Post date:** [November 8, 2018, 4:53am UTC](https://discuss.elastic.co/t/change-the-scoring-function-for-array-using-best-score-for-elements/155807/2 "2018-11-08T04:53:01Z")

</div>

I'm not sure I understand the question.  
For the given query, the document with the given `question` field would be returned as search result. The overall relevancy score for this document would depend on the tf, idf algorithm. There is no other competing field in query so you will get the best score for the document.  
Are you seeing something else?

---

<div class="post-metadata">

**Author:** ![jack1234](https://avatars.discourse-cdn.com/v4/letter/j/9fc29f/32.png) [@jack1234](https://discuss.elastic.co/u/jack1234)\
**Post date:** [November 8, 2018, 9:48am UTC](https://discuss.elastic.co/t/change-the-scoring-function-for-array-using-best-score-for-elements/155807/3 "2018-11-08T09:48:30Z")

</div>

Hi Jaspreet, I want the tf-idf to look at each element in the array (although all of them belong to a field), and return the max value.

---

<div class="post-metadata">

**Author:** ![Jaspreet\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaspreet_singh/32/58296_2.png) [@Jaspreet\_Singh](https://discuss.elastic.co/u/Jaspreet_Singh)\
**Post date:** [November 8, 2018, 2:57pm UTC](https://discuss.elastic.co/t/change-the-scoring-function-for-array-using-best-score-for-elements/155807/4 "2018-11-08T14:57:45Z")

</div>

I my opinion, I do not think there is any difference in the indexing (and subsequent matching) between a regular text datatype or array datatype.  
For example ...

```auto
GET myindex/_analyze
{
  "field":"title",
  "text" : "Cognitive Computing"
}

GET myindex/_analyze
{
  "field":"title",
  "text" : ["Cognitive", "Computing"]
}

```

... yields exactly the same tokens. The specifics are then down to tf idf etc that in turn, as i said do not vary as the basic datatype of both fields is same - string/text.

Are you seeing any difference/unexpected outcome in behaviour?

---

<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:** [December 6, 2018, 2:57pm UTC](https://discuss.elastic.co/t/change-the-scoring-function-for-array-using-best-score-for-elements/155807/5 "2018-12-06T14:57:49Z")

</div>

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