Bug in ElasticSearch (Aggs and moving_fn) v6.6.2

This is my query:

 {
    	"sort": [ { "start_time": { "order": "asc" } } ],
    	"size": 4,
    	"query": {
    		"bool": {
    			"must": [
    				{ "match": { "start_date": "03-22-2019" } },
    				{ "match": { "open": true } }
    			]
    		}
    	},
    	"aggs": {
        	"by-room": {
        		"terms": {
            		"field": "name",
            		"size": 1
        		},
        		"aggs": {
            		"every-interval": {
            			"date_histogram": {
                			"field": "start_datetime",
                			"interval": "30m",
                			"format": "YYYY-MM-DD HH:mm:ss"
            			},
            			"aggs": {
            				"num-taken": {
            					"sum": {
            						"field": "taken"
            					}
            				},
            				"is-available": {
            					"moving_fn": {
    	    						"buckets_path": "num-taken",
    	    						"window": 2,
    	    						"script": "values.length"
            					}
            				}
            			}
            		}
        		}
        	}
        }
    }

I'm Getting back:

{
    "took": 12,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 29,
        "max_score": null,
        "hits": [
{
                "_index": "room1",
                "_type": "timeslots",
                "_id": "63",
                "_score": null,
                "_source": {
                    "name": "room1",
                    "room_id": 1,
                    "date": "2019-03-22",
                    "start_time": "07:30:00",
                    "start_datetime": "2019-03-22 07:30:00",
                    "taken": false,
                    "open": true,
                },
                "sort": [
                    27000000
                ]
            },
            {
                "_index": "room1",
                "_type": "timeslots",
                "_id": "64",
                "_score": null,
                "_source": {
                    "name": "room1",
                    "room_id": 1,
                    "date": "2019-03-22",
                    "start_time": "08:00:00",
                    "start_datetime": "2019-03-22 08:00:00",
                    "taken": false,
                    "open": true,
                },
                "sort": [
                    28800000
                ]
            },
            {
                "_index": "tho_045a",
                "_type": "timeslots",
                "_id": "65",
                "_score": null,
                "_source": {
                    "name": "room1",
                    "room_id": 1,
                    "date": "2019-03-22",
                    "start_time": "08:30:00",
                    "start_datetime": "2019-03-22 08:30:00",
                    "taken": true,
                    "open": true,
                },
                "sort": [
                    30600000
                ]
            },
            {
                "_index": "room1",
                "_type": "timeslots",
                "_id": "66",
                "_score": null,
                "_source": {
                    "name": "room1",
                    "room_id": 1,
                    "date": "2019-03-22",
                    "start_time": "09:00:00",
                    "start_datetime": "2019-03-22 09:00:00",
                    "taken": true,
                    "open": true,
                },
                "sort": [
                    32400000
                ]
            }        ]
    },
    "aggregations": {
        "by-room": {
            "doc_count_error_upper_bound": 0,
            "sum_other_doc_count": 0,
            "buckets": [
                {
                    "key": "room1",
                    "doc_count": 29,
                    "every-interval": {
                        "buckets": [
                            {
                            "key_as_string": "2019-01-22 07:30:00",
                            "key": 1548142200000,
                            "doc_count": 1,
                            "num-taken": {
                                "value": 0,
                                "value_as_string": "false"
                            },
                            "is-available": {
                                "value": 0
                            }
                        },
                        {
                            "key_as_string": "2019-01-22 08:00:00",
                            "key": 1548144000000,
                            "doc_count": 1,
                            "num-taken": {
                                "value": 0,
                                "value_as_string": "false"
                            },
                            "is-available": {
                                "value": 1
                            }
                        },
                        {
                            "key_as_string": "2019-01-22 08:30:00",
                            "key": 1548145800000,
                            "doc_count": 1,
                            "num-taken": {
                                "value": 1,
                                "value_as_string": "true"
                            },
                            "is-available": {
                                "value": 2
                            }
                        }
            },
     ...
}

I used "size 4" to demonstrate what is indexed.

  1. In the buckets the dates are wrong. Should be 2019-03-22 but it's coming back 2019-01-22
  2. The first two buckets in the response has "is-available": { "value": 0 } and "is-available: { "value": 1 } respectively. I expect back (the way I'm making the query -- "script": "values.length" -- along with what exactly is indexed): "is-available": { "value": 2 } and "is-available: { "value": 2 }.

Correct?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.