Aggregation - dateHistogram

Enonic : 6.6.0
OS: Windows

I am struggling with Aggregation on datefields

field: “createdTime” (code below)
works

field: “data.reportedDate”
does not works even if the the date format is exactly the same.

Aggregation on fields under data in case of “terms” seems to work fine. Is there any reason this should not work for dates?

                                  aggregations: {
                                         by_month: {
                                             "dateHistogram": {
                                                field: "createdTime",
                                                interval: "month",
                                                 minDocCount: 0,
                                                 format: "MM-yyyy"
                                             },
                                             aggregations: {
                                                 "categories": {
                                                   "terms": {
                                                     field: "data.productcategory"
                                                   }
                                                 }
                                            }
                                        }
                                    }

Hi.

Could you show me the content-type definition?

There is no content-type definition. Content is unstructured and created from a service. Please see sample-content below.

I want to aggregate (dateHistogram) on data.reportedDate. That does not work. But if I use createdTime, I get it right (but wrong aggregation)

{
“_id”: “77c95a47-aefc-4381-92e0-1f7d3aebdb8a”,
“_name”: “afinion-1169534446554”,
“createdTime”: “2016-10-21T01:44:46.558Z”,
“modifiedTime”: “2016-10-21T01:44:46.558Z”,
“type”: “base:unstructured”,
“data”: {
“productcategory”: “afinion”
“country”: “Albania”,
“product”: “Accessories”,
“status”: “Reported”,
“reportedDate”: “2016-10-21T01:44:46.554Z”,
“updatedDate”: “2016-10-21T01:44:46.554Z”
},
“x”: {},
“page”: {},
“attachments”: {}
}

Ok, the problem us that the field reportedDate is just a string, since there is no mapping defining it to be an Instant.
At the moment, there are no way to specify the types that are not supported by JSON in the unstructured content.

In the upcoming node-api (6.9), we will support advanced data-types when creating data, e.g

 nodeLib.create({
    _name: "myName",
    someData: {
        myInstant: nodeLib.instant("2016-08-01T11:22:00Z"),
        myBinaryReference: nodeLib.binary('myFile', stream1)
   }
}

At the moment, sadly this is not possible for unstructured content, but I guess we will implement the same approach for unstructured content.

So for your current problem, a the solution would be to declare a schema for your data and define the reportedDate as an DateTime. Is that possible, or is the data unstructured by nature?

OK, I understand.

I guess I can create a workaround with a field that can be used for aggregation (terms).

Thanks!