# Inner Hits and Rescoring

**URL:** <https://discuss.elastic.co/t/inner-hits-and-rescoring/207745>\
**Category:** Elasticsearch\
**Created:** [November 13, 2019, 4:24pm UTC](https://discuss.elastic.co/t/inner-hits-and-rescoring/207745 "2019-11-13T16:24:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ravensedge](https://avatars.discourse-cdn.com/v4/letter/r/f17d59/32.png) [@ravensedge](https://discuss.elastic.co/u/ravensedge)\
**Post date:** [November 13, 2019, 4:24pm UTC](https://discuss.elastic.co/t/inner-hits-and-rescoring/207745/1 "2019-11-13T16:24:39Z")

</div>

Hi all,

I have the following problem: I want to do filtering on a nested field, then rescore based on the fields that matched the filter.

In the minimum working example below, the query returns a score of 9000. However, I would like it to only return 5 as 5 is the only inner value that matches the initial query of \< 70.

```
PUT testing_index
{
  "mappings": {
    "doc": {
      "properties": {
        "inner": {
          "type": "nested"
        }
      }
    }
  }
}

PUT testing_index/doc/1
{
  "value": 3,
  "inner": [
    {
      "inner_value": 5
    },
    {
      "inner_value": 9000
    }
  ]
}

GET testing_index/_search
{
  "query": {
    "nested": {
      "path": "inner",
      "query": {
        "range": {
          "inner.inner_value": {
            "lt": 70
          }
        }
      }
    }
  },
  "rescore": {
    "query": {
      "rescore_query": {
        "nested": {
          "path": "inner",
          "query": {
            "function_score": {
              "field_value_factor": {
                "field": "inner.inner_value"
              }
            }
          },
          "score_mode": "max"
        }
      },
      "query_weight": 0,
      "rescore_query_weight": 1
    }
  }
}

```

The rescore is absolutely necessary. In my use case, there are billions of documents and the rescoring function is expensive. This means I have to write an initial function score, take the top 10000 or so candidates and then run the rescore.

Thanks!

---

<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 11, 2019, 4:24pm UTC](https://discuss.elastic.co/t/inner-hits-and-rescoring/207745/2 "2019-12-11T16:24:43Z")

</div>

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