We have a requirement to override default elastic score mechanism and score two documents equally if they have equal number of matches ignoring tf and idf.
Below is my sample index data
PUT my_index/_doc/5
{
"affinity": {
"visitorSegments": [
"TPRO",
"LPRO"
],
"category": [
"kitchen",
"corridor"
]
},
"sets": [
{
"visitorSegments": "TPRO",
"category" : "kitchen",
"engagementScore": "0.5"
},
{
"visitorSegments": "LPRO",
"category" : "kitchen",
"engagementScore": "0.4"
},
{
"visitorSegments": "LPRO",
"category" : "corridor",
"engagementScore": "0.1"
}
],
"distinctaffinities": 2
}
PUT my_index/_doc/6
{
"affinity": {
"visitorSegments": [
"TPRO"
],
"category": [
"kitchen"
]
},
"distinctaffinities": 2
}
Each document is tagged to some visitorSegments and categories. And also an array with possible combinations of values from visitorSegments and category with an enagagementScore.
I am trying the below Query
GET my_index/_search
{
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"function_score": {
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"must": [
{
"match_phrase": {
"affinity.visitorSegments": "TPRO"
}
}
]
}
},
{
"bool": {
"must": [
{
"match_phrase": {
"affinity.category": "kitchen"
}
}
]
}
}
]
}
},
"functions": [
{
"filter": {
"match": {
"affinity.category": "kitchen"
}
},
"weight": 3
},
{
"filter": {
"match": {
"affinity.visitorSegments": "TPRO"
}
},
"weight": 1
},
{
"filter": {
"bool": {
"must": [
{
"match": {
"sets.visitorSegments": "TPRO"
}
},
{
"match": {
"sets.category": "kitchen"
}
}
]
}
},
"weight": //dynamic value for engagementScore for matching entry from sets[]
}
],
"score_mode": "sum",
"boost_mode": "replace"
}
}
]
}
}
}
I need to get the value engagementScore from the array entry under sets and set that as value to weight under the third filter statement. So my score should be addition of all three weight statement but third weight value needs to be referred from inside the document only something like
weight : "doc['sets.engagementScore]" and overall expecting score of 3 + 1 + 0.5 = 4.5
Able to get score for 4, but unable to get the additional 0.5