Closed ComLock closed 1 year ago
@ComLock Can you give us an example of how this should look?
doc: https://developer.enonic.com/docs/xp/stable/storage/aggregations#daterange
{
"my_date_range": {
"dateRange": {
"field": "date",
"format": "yyyy-MM-dd",
"ranges": [
{
"from": "now-1H",
"to": "now",
"name": "last_hour",
"displayName": 'Last hour'
},
{
"from": "now-1d",
"to": "now-1H",
"name": "last_day",
"displayName": 'Last day'
}
]
}
}
}
Then my code can relate to static bucket names, rather than dynamic named key field.
I can see how name adds value, but I think displayName is not relevant (this is a presentation issue). @runarmyklebust any reason why this would not be supported by XP?
@runarmyklebust any comments to this?
This is supported by ES v6+, before that its a bit tricky to support:
It is also possible to customize the key for each range:
POST /sales/_search?size=0
{
"aggs": {
"range": {
"date_range": {
"field": "date",
"format": "MM-yyy",
"ranges": [
{ "from": "01-2015", "to": "03-2015", "key": "quarter_01" },
{ "from": "03-2015", "to": "06-2015", "key": "quarter_02" }
],
"keyed": true
}
}
}
}
Response:
{
...
"aggregations": {
"range": {
"buckets": {
"quarter_01": {
"from": 1.4200704E12,
"from_as_string": "01-2015",
"to": 1.425168E12,
"to_as_string": "03-2015",
"doc_count": 5
},
"quarter_02": {
"from": 1.425168E12,
"from_as_string": "03-2015",
"to": 1.4331168E12,
"to_as_string": "06-2015",
"doc_count": 2
}
}
}
}
}
To be discussed in the scope of XP 8.
Implemented and tested working: https://github.com/enonic/xp/blob/master/modules/lib/core/index.d.ts#L370
Lets say you want to make a facet (aggregations + filters) on a timestamp field.
You would like the ranges to be:
The aggregation ranges are not too difficult to make using the Date-math (now-1d).
However when it comes time to process them and generate filters for them and toggle those filters things become a lot more complex.
I think it would simplify the code a lot if you could supply another parameter in addition to "from" and "to" to set a unique bucket "name" in the configuration.
Since Date-math is used none of the bucket fields are static, they can change between queries.
In my case the facets are client-side react with internal state, so operating with object keys that are non-static becomes near impossible. You turn on a facet, but since time has passed that facet no longer exists...
I guess you could base the facets on the aggregation bucket index if the number of buckets is static. But that might not be the case. So I would like to be able to specify a name to make things more understandable.
It would even be nice to specify a displayName to use clientSide.