hi Hendrik,
I tried your suggestion but I'm not able to get the desired output . For input data -
{
"_index": "latest-transactions",
"_id": "NnLULrwn4Me522lTlVzUwIbJAAAAAAAA",
"_score": 1,
"_source": {
"ingest_time": "2022-07-11T13:43:28.554096099Z",
"transactionReferenceNumber": "ref1",
"warningDescriptions": "Reported - non-MiFID eligibleeee",
"submissionAccountName": "ACCOUNT1",
"warnings": "W6009",
"assetClass": "EQUI",
"initial_ingest_time": "2022-07-11T13:43:28.554096099Z",
"tradeDateTime": "2022-07-11T13:07:39.137029349Z",
"regulator": "BaFIN",
"instructionId": "ins1",
"payload_ts": "1657530982219",
"executingEntityIdCode": "635400BDQCJNMOGTBB61",
"status": "NEW"
}
},
{
"_index": "latest-transactions",
"_id": "NnJtzRgray9JKJWDQ3aQCIE7AAAAAAAA",
"_score": 1,
"_source": {
"ingest_time": "2022-07-11T13:50:26.865951666Z",
"transactionReferenceNumber": "ref3",
"warningDescriptions": "Reported - non-MiFID eligibleeee",
"submissionAccountName": "ACCOUNT1",
"warnings": "W6009",
"assetClass": "EQUI",
"initial_ingest_time": "2022-07-10T13:35:54.884067700Z",
"tradeDateTime": "2022-07-10T13:07:39.137029349Z",
"regulator": "BaFIN",
"instructionId": "ins3",
"payload_ts": "1657411200000",
"executingEntityIdCode": "635400BDQCJNMOGTBB61",
"status": "NEW-updated"
}
},
{
"_index": "latest-transactions",
"_id": "NnIsJ6ZK7KWrrvyEazVThqIcAAAAAAAA",
"_score": 1,
"_source": {
"ingest_time": "2022-07-11T15:25:10.473393438Z",
"transactionReferenceNumber": "ref2",
"warningDescriptions": "Reported - non-MiFID eligibleeee",
"submissionAccountName": "ACCOUNT1",
"warnings": "W6009",
"assetClass": "BOND",
"initial_ingest_time": "2022-07-11T13:43:37.870259331Z",
"tradeDateTime": "2022-07-11T13:07:39.137029349Z",
"regulator": "BaFIN",
"instructionId": "ins2",
"payload_ts": "1657530982219",
"executingEntityIdCode": "635400BDQCJNMOGTBB61",
"status": "NEW-2"
}
},
{
"_index": "latest-transactions",
"_id": "NnLvT60H82772ZWc0douckcuAAAAAAAA",
"_score": 1,
"_source": {
"initial_ingest_time": "2022-07-13T12:59:54.278717796Z",
"ingest_time": "2022-07-13T12:59:54.278717796Z",
"transactionReferenceNumber": "ref4",
"submissionAccountName": "ACCOUNT1",
"tradeDateTime": "2022-07-08T13:07:39.137029349Z",
"regulator": "BaFIN",
"instructionId": "ins4",
"assetClass": "EQUI",
"payload_ts": "1657717128548",
"executingEntityIdCode": "635400BDQCJNMOGTBB61",
"status": "NEW"
}
}
]
I have this transform -
POST _transform/_preview
{
"source": {
"index": "latest-transactions"
},
"pivot": {
"group_by": {
"tradeDateTime": {
"date_histogram": {
"field": "tradeDateTime",
"calendar_interval": "1m"
}
},
"executingEntityIdCode": {
"terms": {
"field": "executingEntityIdCode.keyword"
}
}
},
"aggs": {
"status": {
"terms": {
"field": "status.keyword"
},
"aggs": {
"tm": {
"top_metrics": {
"metrics": [
{
"field": "submissionAccountName.keyword"
},
{
"field": "assetClass.keyword"
},
{
"field": "regulator.keyword"
},
{
"field": "status.keyword"
}
],
"sort": {
"ingest_time": "desc"
}
}
}
}
},
"status_count": {
"value_count": {
"field": "status.keyword"
}
}
}
}
}
and result is
{
"preview": [
{
"tradeDateTime": "2022-07-08T13:07:00.000Z",
"status_count": 1,
"executingEntityIdCode": "635400BDQCJNMOGTBB61",
"status": {
"NEW": {
"tm": {
"submissionAccountName.keyword": "ACCOUNT1",
"assetClass.keyword": "EQUI",
"regulator.keyword": "BaFIN",
"status.keyword": "NEW"
}
}
}
},
{
"tradeDateTime": "2022-07-10T13:07:00.000Z",
"status_count": 1,
"executingEntityIdCode": "635400BDQCJNMOGTBB61",
"status": {
"NEW-updated": {
"tm": {
"submissionAccountName.keyword": "ACCOUNT1",
"assetClass.keyword": "EQUI",
"regulator.keyword": "BaFIN",
"status.keyword": "NEW-updated"
}
}
}
},
{
"tradeDateTime": "2022-07-11T13:07:00.000Z",
"status_count": 2,
"executingEntityIdCode": "635400BDQCJNMOGTBB61",
"status": {
"NEW": {
"tm": {
"submissionAccountName.keyword": "ACCOUNT1",
"assetClass.keyword": "EQUI",
"regulator.keyword": "BaFIN",
"status.keyword": "NEW"
}
},
"NEW-2": {
"tm": {
"submissionAccountName.keyword": "ACCOUNT1",
"assetClass.keyword": "BOND",
"regulator.keyword": "BaFIN",
"status.keyword": "NEW-2"
}
}
}
}
],
Is there a way for me to know the count of unique status values in a map (may be) - like this
status{
New: 1
New-2 : 1
}
I am trying to put this whole output in a sub aggregation and run a scripted metric to traverse the status field and store occurrences in a map but it's failing syntactically.