Nested aggregation of runtime nested field returns empty buckets

Before I describe the issue, it's worth noting that this issue is happening at the end of a long process of migrating a 2.4 ES cluster to 7.12, with multiple updates to mappings and queries, so please have in mind that I might be missing something very stupid here.

I have a mapping with a nested field that is mapped at runtime (created using ES' Java API), which was previously used without any issues. However, as of now, the same query gets this specific aggregation to return with empty buckets.

Mapping:

    "products": {
        "mappings": {
            "runtime": {
                "categories.group": {
                    "type": "long"
                },
                "categories.subclass": {
                    "type": "long"
                },
                "categories.subgroup": {
                    "type": "long"
                }
        },
        "properties": {
            "type": {
                "type": "constant_keyword",
                "value": "product"
            },
            "group": {
                "type": "integer"
            },
            "categories": {
                "type": "nested",
                "dynamic": "runtime"
            },
            ... other properties

Query that showcases the issue:

    {
        "from": 0,
        "size": 48,
        "query": {
            "bool": {
                "must": [
                    {
                        "match": {
                            "tipo": {
                                "query": "product"
                            }
                        }
                    },
                    {
                        "match": {
                            "group": {
                                "query": 2
                            }
                        }
                    }
                ],
                "adjust_pure_negative": true,
                "boost": 1.0
            }
        },
        "aggs": {
            "groups": {
                "nested": {
                    "path": "categories"
                },
                "aggs": {
                    "group": {
                        "terms": {
                            "field": "categories.group"
                        }
                    }
                }
            }
        }
    }

The query works as expected, returning the hits it should, with the sole exception of the nested aggregation (the original query has about 8 aggs, with the others returning the buckets expected), which yields something similar to this:

    "aggregations": {
        "groups": {
            "doc_count": 3072,
            "group": {
                "doc_count_error_upper_bound": 0,
                "sum_other_doc_count": 0,
                "buckets": []
            }
        }
    }

I've gone through multiple possible solutions across the web but none of them worked so far. What leads me to believe it might be related to the "dynamic: runtime" mapping is that we do have another nested property with basically the same structure that can actually be queried with the usual nested query, with the sole difference that this one is statically mapped when the index is created.

I've been stuck on this issue for the past couple days, so any idea is a huge help.

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