Multiple Nested paths inside the Functions - Function Score Query


(Mahathi Bhagavatula) #1

I have a use case where the data is stored in multiple nested fields. As shown below:

{ "field1":
{ "sub_field1": "string",
"sub_field2":"string"
},
{ "sub_field1" :"string",
"sub_field2":"string"
}
},
{"field2":
{ "new_field1": "string",
"new_field2":"string"
},
{ "new_field1" :"string",
"new_field2":"string"
}
}
Now, for each "query_str" I have to query all these nested fields and get the max (scores) w.r.t all these fields and I have to calculate the sum of all such query_str

This problem can be broken down into two sub problems :

  1. For each Function Score Query, I can have different functions such that, each function should point out to each nested path. This will look some thing like below:

{
"query": {
"function_score": {
"functions": [
{ "query":{
"nested": {
"path": "field1",
"query": {
"filter": { "term": { "field1.sub_field1": "query_str" }},
"weight": 1 }}}
},
{ "query":{
"nested": {
"path": "field2",
"query": {
"filter": { "term": { "field2.new_field1": "query_str" }},
"weight": 1 }}}
} ],
"score_mode":"max"
}
}
}

  1. Nested Score_modes:- after the above query, I will get some thing like max (scores) for one query string "query_str". Now, I need an addition of all such maximum scores for different query strings.

To summarize mathematically,

final_score = Sum on all queries ( for each_ query max ( score_on_field1, score_on_field2))


(system) #2

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