How to aggregate runtime_mappings fields

Hi,
I'm trying to join two indices using the runtime_mappings as described here. The join seems OK however the aggregation always returns 0. Can someone help ? Here is the code :

POST parent_index/_search
{
  "size": 0,
  "runtime_mappings": {
    "my_mapping": {
      "type": "lookup",
      "target_index": "child_index",
      "input_field": "parent_key",
      "target_field": "child_foreign_key",
      "fetch_fields": [
        "id",
        "sales",
      ]
    }
  },
  "aggregations": {
    "per_id": {
      "terms": {
        "field": "id.keyword"
      },
      "aggregations": {
        "per_sales": {
          "sum": {
            "field": "my_mapping.sales"
          }
        }
      }
    }
  },
  "_source": false
}

I have 2 parent documents and 2 child documents. The two child documents are linked to one parent therefore one parent should have a total of 0 'per_sales' and the other parent more than 0 in the 'per_sales' aggregation.

I got this result which is not correct:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 2,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  },
  "aggregations": {
    "per_id": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "parent_key_1",
          "doc_count": 1,
          "per_sales": {
            "value": 0
          }
        },
        {
          "key": "parent_key_2",
          "doc_count": 1,
          "per_sales": {
            "value": 0
          }
        }
      ]
    }
  }
}

PS: I'm using Elasticsearch 8.4 on Ubuntu 20.04.
Thanks

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