Closed LantaoJin closed 2 months ago
@LantaoJin
Please correct me if my understanding here is wrong, but it looks like your agg is on the field patients.name.keyword
but from the document it should just be patients.name
.
Furthermore, when I try to do your value_count
agg on just patients.name
, I get the following:
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [patients.name] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
}
]
Given that I don't think there are any problems here then, could you please double check?
Also, I think in order to interact with nested fields in an aggregation, a nested aggregation must be used. See: https://opensearch.org/docs/latest/aggregations/bucket/nested/
@jed326, @mch2, I test this, it'ok, it seems not a problem.
GET test_nested_field_index/_search
{
"aggs": {
"patients1": {
"nested": {
"path": "patients"
},
"aggs": {
"aggs1": {
"value_count": {
"field": "patients.name.keyword"
}
}
}
}
}
}
Thanks @kkewwei! I also took at look at this, I think the problem is the nested aggregation was not used in the original query. I'm going to close this issue for now, @LantaoJin please re-open if there's any other issues here, thanks!
Describe the bug
Aggregation
value_count
on field ofnested
type returns incorrect result. This issue only happens onnested
type,object
type withoutnested
looks fine.Related component
Search:Aggregations
To Reproduce
Repro:
Expected behavior
value_count
should return 2 instead of 0Additional Details
Plugins Please list all plugins currently enabled.
Screenshots If applicable, add screenshots to help explain your problem.
Host/Environment (please complete the following information):
Additional context Add any other context about the problem here.