# Aggregating relevance \_score with nested text fields

**URL:** <https://discuss.elastic.co/t/aggregating-relevance-score-with-nested-text-fields/243892>\
**Category:** Elasticsearch\
**Created:** [August 5, 2020, 3:31pm UTC](https://discuss.elastic.co/t/aggregating-relevance-score-with-nested-text-fields/243892 "2020-08-05T15:31:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zp230](https://avatars.discourse-cdn.com/v4/letter/z/4da419/32.png) [@zp230](https://discuss.elastic.co/u/zp230)\
**Post date:** [August 5, 2020, 3:31pm UTC](https://discuss.elastic.co/t/aggregating-relevance-score-with-nested-text-fields/243892/1 "2020-08-05T15:31:58Z")

</div>

I am having difficulties finding documentation or discussions about how to aggregate the \_score field for nested text fields. The structure of my index includes one nested field. The structure of a single document is a long text with meta parameters in the "parent" level, and the text's individual sentences (tuple [text, label]) in a nested "text" field. The structure of my \_search is as follows:

1. SEARCH: Nested query that matches a search term with the nested text fields. (ie. does the sentence include this search term?) Note, that using inner\_hits, I can see that each nested text sentence in a single parent document is scored individually (they have different scores).
2. AGGREGATE: bucket the documents on one of the parent variables, and then within those buckets, bucket the nested fields based on the label of the sentence, and average the \_score of the sentences inside.

However, what I'm finding is that at the end of the search query and _before_ aggregation, the parent document gets assigned a \_score that is the average (score\_mode: average) of the matching sentence \_scores. Then, in aggregation, all of the nested sentences of a single parent document have the same average \_score, and the individual score is _lost_.

Is there any way to use the individual non-averaged \_score on the nested text fields in aggregation, or will it always use the averaged parent \_score for each nested sentence? Would it change anything to use parent-child instead of a nested structure?

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:** [September 2, 2020, 3:32pm UTC](https://discuss.elastic.co/t/aggregating-relevance-score-with-nested-text-fields/243892/2 "2020-09-02T15:32:00Z")

</div>

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