Skip to content

Instantly share code, notes, and snippets.

@dmitry dmitry/date.md
Last active Oct 2, 2016

Embed
What would you like to do?
elasticsearch date historgram
curl -XGET 'http://localhost:42001/bookings/booking/_search?&pretty=true' -d '{
  "aggs": {
    "test": {
      "filter": {
        "terms": {
          "status": ["accepted"]
        }
      },
      "aggs": {
        "union_demo": {
          "date_histogram": {
            "interval": "day",
            "script": "\"2016-01-01\"",
            "min_doc_count": 1
          }
        }
      }
    }
  }
}'

var logger = org.elasticsearch.common.logging.ESLoggerFactory.getLogger(\"myscript\");   var dates = [];var end_date = new Date(doc.end_date.value);logger.info(new Date(doc.start_date.value));var current = new Date(doc.start_date.value);while (current <= end_date) {  dates.push(current);  current = new Date(current.getFullYear(), current.getMonth(), current.getDate() + 1);}dates

new Date( doc[\"aDate\"].value )


doc['start_date'].value + doc['end_date'].value"   


"

var logger = org.elasticsearch.common.logging.ESLoggerFactory.getLogger(\"myscript\");
logger.info(new Date( doc[\"start_date\"].value ));   

doc[\"start_date\"].value
"


		"range": {
			"start_date": {
				"gte": "now"
			}
        },

var dates = [];
var end_date = new Date(doc.end_date.value);
var current = new Date(doc.start_date.value);
while (current <= end_date) {
  dates.push(current);
  current = new Date(current.getFullYear(), current.getMonth(), current.getDate() + 1);
}
dates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.