# Multiple Nested paths inside the Functions - Function Score Query

**URL:** <https://discuss.elastic.co/t/multiple-nested-paths-inside-the-functions-function-score-query/66058>\
**Category:** Elasticsearch\
**Created:** [November 15, 2016, 6:12am UTC](https://discuss.elastic.co/t/multiple-nested-paths-inside-the-functions-function-score-query/66058 "2016-11-15T06:12:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mahathi\_bhagavatula](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@mahathi\_bhagavatula](https://discuss.elastic.co/u/mahathi_bhagavatula)\
**Post date:** [November 15, 2016, 6:12am UTC](https://discuss.elastic.co/t/multiple-nested-paths-inside-the-functions-function-score-query/66058/1 "2016-11-15T06:12:25Z")

</div>

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,  
 ![](https://us1.discourse-cdn.com/elastic/original/2X/3/3a64ae98eb29eb79309cd26154f57a1a1dedd5cf.jpg)

final\_score = Sum on all queries ( for each\_ query max ( score\_on\_field1, score\_on\_field2))

---

<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 13, 2016, 6:12am UTC](https://discuss.elastic.co/t/multiple-nested-paths-inside-the-functions-function-score-query/66058/2 "2016-12-13T06:12:40Z")

</div>

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