my doc was like the following format, i didnt do any mapping but it come out different when i use two field to perform the top hit aggregations
"max_score": 1.0,
"hits": [
{
"_index": "data",
"_type": "test",
"_id": "UzzwY3cBOTCkvi7mN2VG",
"_score": 1.0,
"_source": {
"hdId": 20210120,
"hrId": 5348,
"timestamp": 1612289417551,
"timestampstring": "2021-02-03 02:10:17.551",
"ooId": "672848824",
"okCount": 17,
"totalVol": 4220842,
"type": "test"
}
}
]
And i want to use the "Top hit" aggregations to find out the latest record of each ID my query was like
{
"query": {
"bool": {
"must": {
"terms": {
"ooId": [672848824,672848823]
}
},
"filter": {
"match": {
"type": "test"
}
}
}
},
"size": 1,
"aggs": {
"unique_id": {
"terms": {
"field": "ooId",
"size": 1
},
"aggs": {
"top_result": {
"top_hits": {
"size": 1,
"_source": ["ooId","totalVol","okCount"],
"sort": {
"timestamp" : "desc"
}
}
}
}
}
}
}
when i do the about query, it shows the ERROR
{
"error": {
"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 [ooId] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "test",
"node": "CzM0ERKGTVyQc3mSiRBY2A",
"reason": {
"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 [ooId] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
}
}
],
"caused_by": {
"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 [ooId] in order to load field data by uninverting the inverted index. Note that this can use significant memory.",
"caused_by": {
"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 [ooId] in order to load field data by uninverting the inverted index. Note that this can use significant memory."
}
}
},
"status": 400
}
But when i use another field "hdId" replacing "ooId"to do the query it go without error
like`
"aggs": {
"unique_id": {
"terms": {
"field": "hdId",
"size": 1
},
and it come out ok
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 104,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"unique_id": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": 20210119,
"doc_count": 54,
"top_result": {
"hits": {
"total": {
"value": 54,
"relation": "eq"
},
"max_score": null,
"hits": [
{
"_index": "data",
"_type": "test",
"_id": "jk4bXHgBsdomP0OQIkT1",
"_score": null,
"_source": {
"totalVol": 29613406,
"ooId": "672848823",
"okCount": 64
},
"sort": [
1616452982797
]
}
]
}
}
},
{
"key": 20210120,
"doc_count": 50,
"top_result": {
"hits": {
"total": {
"value": 50,
"relation": "eq"
},
"max_score": null,
"hits": [
{
"_index": "data",
"_type": "test",
"_id": "FU4dW3gBsdomP0OQwCdo",
"_score": null,
"_source": {
"totalVol": 29296696,
"ooId": "672848824",
"okCount": 66
},
"sort": [
1616436374297
]
}
]
}
}
}
]
}
}
}
how can i fix the error as i dont want to use hdId as the query parameter ,
thanks
Jeff