# Score based on term existing or not in multiple fields

**URL:** <https://discuss.elastic.co/t/score-based-on-term-existing-or-not-in-multiple-fields/94796>\
**Category:** Elasticsearch\
**Created:** [July 27, 2017, 12:59pm UTC](https://discuss.elastic.co/t/score-based-on-term-existing-or-not-in-multiple-fields/94796 "2017-07-27T12:59:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![elastic\_newb](https://avatars.discourse-cdn.com/v4/letter/e/97f17d/32.png) [@elastic\_newb](https://discuss.elastic.co/u/elastic_newb)\
**Post date:** [July 27, 2017, 12:59pm UTC](https://discuss.elastic.co/t/score-based-on-term-existing-or-not-in-multiple-fields/94796/1 "2017-07-27T12:59:40Z")

</div>

I have the following data:  
{  
"\_index": "myindex",  
"\_type": "mytype",  
"\_id": "1",  
"\_source": {  
"field1": "word1 word2 word3",  
"field2": "word1 word2 word3",  
"field3": "word1 word2 word3"  
}  
}  
{  
"\_index": "myindex",  
"\_type": "mytype",  
"\_id": "2",  
"\_source": {  
"field1": "word1 word2 word3",  
"field2": "word3 word4 word5",  
"field3": "word5 word6 word7"  
}  
}  
{  
"\_index": "myindex",  
"\_type": "mytype",  
"\_id": "3",  
"\_source": {  
"field1": "word1 word2 word3",  
"field2": "word4 word5 word6",  
"field3": "word7 word8 word9"  
}  
}

What I am trying to obtain is a custom score based on the presence of the searched word in the fields.  
For example, searching for "word3" should return id 1 with a score of 3 (since it's present in all 3 fields), then id 2 with a score of 2, since it's present only in field1 and field2, followed by id 3 with a score of 1.

Extrapolating, searching for "word1 word3" should return id 1 with a score of 6 (word1 contained in 3 fields plus word3 contained in 3 fields for a total of 6), id 2 with a score of 3 (word1 contained in 1 field plus word3 contained in 2 fields), id 3 with a score of 2 (one word1 and one word3).

Is this possible ?  
PS. I am not interested if for example word1 is repeated in the same field multiple times, the score should be by presence, not count.

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:** [August 24, 2017, 1:00pm UTC](https://discuss.elastic.co/t/score-based-on-term-existing-or-not-in-multiple-fields/94796/2 "2017-08-24T13:00:03Z")

</div>

Closed on August 24, 2017, 1:00pm UTC

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