Hello,
I am trying to provide a solution for this stackoverflow question.
`PUT http://localhost:9200/test_index/test/_mapping/`
{
"test": {
"properties": {
"date": {
"type": "date",
"format": "strict_date_optional_time||epoch_millis"
},
"status": {
"type": "string",
"index": "not_analyzed"
},
"version": {
"type": "long"
},
"workFlowId": {
"type": "long"
}
}
} }
Then index all the data shown in question (total 10) one by one.
POST http://localhost:9200/test_index/test/1
{
"date" : "2015-11-01",
"workFlowId" : 1,
"version" : 1,
"status": "In Progress"
}
I tried Bucket Script Aggregation and Sub Aggregation as follow:
POST http://localhost:9200/test_index/test/_search?search_type=count
{
"aggs": {
"per_day": {
"date_histogram": {
"field": "date",
"interval": "day"
},
"aggs": {
"per_status": {
"terms": {
"field": "status"
},
"aggs": {
"max_version_per_workflow": {
"terms": {
"field": "workFlowId"
},
"aggs": {
"max_version": {
"max": {
"field": "version"
}
},
"eod_bucket_filter": {
"bucket_selector": {
"buckets_path": {
"maxVersionPerWorkFlow": "max_version"
},
"script": "2 >= maxVersionPerWorkFlow"
}
}
}
}
}
}
}
}
}
}
Which is working fine I guess and giving expected results. For each day I need to find out total "In Progress" and "Completed" workflows considering only records that has largest version till that day. . Keeping that in mind, I am using bucket filter. But as you see, in script I used static value 2
. Instead of that I need to use document's version
value for comparison. Here doc['title'].value
is not working. Any suggestion how I can achieve this?