Inverted index is the mapping of terms to document whereas field-data/doc values is the mapping of documents to terms. In inverted index for a field, unique values of that field in the index is the key whereas in field-data document IDs is the key. Now while aggregations we create buckets based on the field values which we don't know beforehand.
My question is isn't there a function like getKeys() to get all the keys of the inverted index which will be the unique values of a field in that index and then using each value of this set to access an entry in the inverted index and traverse through the list of documents which are mapped to this key in the inverted index and update the buckets ?
I know this is not how it happens today and I'm guessing that there is a good reason for not doing so, I'm interested in knowing that reason.