Top_hits aggregation on a serial_diff


(Stephanbuys) #1

I've got a complex nested aggregation that uses a serial_diff as final step to produce a new field. This field contains the information I want to visualise.

Unfortunately I can't get top_hits to recognise the field created by serial_diff, is there a way to specify that path or will I have to calculate the top_hits myself on the client side? (Any pseudo code? :slight_smile: )

Thanks!

The query looks something like:
POST /index/type/_search
{
"size": 0,
"query": {...
},
"aggs": {
"agg1": {
"terms": {
"field": "field1.raw",
"size": 0
},
"aggs": {
"agg2": {
"terms": {
"field": "field2.raw",
"size": 0
},
"aggs": {
"timechart": {
"date_histogram": {
...
},
"aggs": {
"max_field_of_interest": {
"max": {
"field": "field_of_interest"
}
},
"usable_value": {
"serial_diff": {
"buckets_path": "max_field_of_interest",
"lag": 1
},
"aggs": {
"top_results": {
"top_hits": {
"sort": [
{
"usable_value": {
"order": "desc"
}
}
],
"size" : 10
}
...
}


(Mike Paduada) #2

The top_hits aggregation will return a subset of documents within the bucket. Your usable_value serial-differencing aggregation returns a metric based on the set of documents in the current bucket and in the immediately preceding bucket, which is to say that there is one value for usable_value per bucket, not per document. So, syntax aside, it doesn't make sense to sort documents in the bucket based on usable_value.

Can you clarify what you're trying to collect with your top_hits aggregation?


(system) #3