# Convert MySQL query to elasticsearch

**URL:** <https://discuss.elastic.co/t/convert-mysql-query-to-elasticsearch/40830>\
**Category:** Kibana\
**Created:** [February 3, 2016, 7:32am UTC](https://discuss.elastic.co/t/convert-mysql-query-to-elasticsearch/40830 "2016-02-03T07:32:57Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![tbragin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tbragin/32/45166_2.png) [@tbragin](https://discuss.elastic.co/u/tbragin)\
**Post date:** [February 10, 2016, 10:46pm UTC](https://discuss.elastic.co/t/convert-mysql-query-to-elasticsearch/40830/15 "2016-02-10T22:46:33Z")

</div>

You may need to do something more complicated, such as pass a [script to the date aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/2.2/search-aggregations-bucket-datehistogram-aggregation.html#_scripts) in order to do some calculations across the returned buckets.

Notice in the example I linked to in the [thread](https://discuss.elastic.co/t/display-concurrency-in-data-on-kibana/26006/15) above, the script actually goes through values returned in the buckets and calculates an array of durations, returning that as a result:

```auto
start = doc['recordStart'].value; 
duration = doc['recordDuration'].value; 
l = []; 
for (long i = 0; i < duration; i += 60000) 
	{ l.add(start + i); }; 
return l;

```

---

_[View the full topic](https://discuss.elastic.co/t/convert-mysql-query-to-elasticsearch/40830)._
