Opensearch flat_object aggregations not working

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):
opensearch 2.11.0 (latest) using docker compose

Describe the issue:
I am unable to generate term aggregations on flat_object fields. I posted on stackoverflow (here) already and then realized there was this forum :man_facepalming: . so here it goes …

I have an index with the following mappings :

"mappings": {
     "properties": {
        "zip5": {
          "type": "keyword"
        },
        "labels": {
          "type": "flat_object"
        }
      }
    }

Then I push some docs :

PUT test_agg_1/_doc/1
{
  "zip5": "1000",
  "labels": {
    "colour" : "red"
  }
}

PUT test_agg_1/_doc/2
{
  "zip5": "1001",
  "labels": {
    "colour" : "blue"
  }
}

PUT test_agg_1/_doc/3
{
  "zip5": "1001",
  "labels": {
    "colour" : "blue"
  }
}

Then run the query and get aggregations on zip5 and labels.colour:

GET test_agg_1/_search
{
  "track_total_hits": true,
  "query": {
    "bool": {
      "must": [
        {
          "bool":{
            "should": [
              {"match": {"labels.colour": "blue"}},
              {"match": {"labels.colour": "red"}}
            ]
          }
        },
        {
          "terms": {"zip5":["1001","1000"]}
        }
      ]
    }
  },
  "aggs":{
    "colour":{
      "terms":{"field":"labels.colour"}
    },
    "zip":{
      "terms":{"field":"zip5"}
    }
  }
}

response

{
  "took": 5,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 3,
      "relation": "eq"
    },
    "max_score": 1.9808291,
    "hits": [
      {
        "_index": "test_agg_1",
        "_id": "1",
        "_score": 1.9808291,
        "_source": {
          "zip5": "1000",
          "labels": {
            "colour": "red"
          }
        }
      },
      {
        "_index": "test_agg_1",
        "_id": "2",
        "_score": 1.4700036,
        "_source": {
          "zip5": "1001",
          "labels": {
            "colour": "blue"
          }
        }
      },
      {
        "_index": "test_agg_1",
        "_id": "3",
        "_score": 1.4700036,
        "_source": {
          "zip5": "1001",
          "labels": {
            "colour": "blue"
          }
        }
      }
    ]
  },
  "aggregations": {
    "zip": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "1001",
          "doc_count": 2
        },
        {
          "key": "1000",
          "doc_count": 1
        }
      ]
    },
    "colour": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": []
    }
  }
}

You can see the colour aggregation is empty when it should not. If I do this in elasticsearch instead and use a “flattened” type for labels it works. Is this not supported at opensearch or am I missing something ?

Thanks!

ok, I hit this :
" * Aggregations of subfields using dot notation." (here)

I guess the question is now if there is a way to do this with a flat_object without the dot notation ?