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.