Inner Hits and Rescoring

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!

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