# Scripting in date histogram

**URL:** <https://discuss.elastic.co/t/scripting-in-date-histogram/14343>\
**Category:** Elasticsearch\
**Created:** [November 11, 2013, 5:46am UTC](https://discuss.elastic.co/t/scripting-in-date-histogram/14343 "2013-11-11T05:46:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11134](https://avatars.discourse-cdn.com/v4/letter/1/65b543/32.png) [@11134](https://discuss.elastic.co/u/11134)\
**Post date:** [November 11, 2013, 5:46am UTC](https://discuss.elastic.co/t/scripting-in-date-histogram/14343/1 "2013-11-11T05:46:22Z")

</div>

my curl request is  
curl -XGET '[http://172.18.216.60:9200/resource/\_search?pretty](http://172.18.216.60:9200/resource/_search?pretty)' -d '{  
"facets": {  
"0": {  
"date\_histogram": {  
"key\_field": "timestamp",  
"value\_script": "doc[\u0027record\u0027].value",  
"interval": "12h"  
},  
"facet\_filter": {  
"fquery": {  
"query": {  
"filtered": {  
"query": {  
"query\_string": {  
"query": "01A"  
}  
},  
"filter": {  
"bool": {  
"must": [  
{  
"match\_all": {}  
},  
{  
"fquery": {  
"query": {  
"field": {  
"bid": {  
"query": ""110105C999""  
}  
}  
},  
"\_cache": true  
}  
},  
{  
"range": {  
"timestamp": {  
"from": 1380689917897,  
"to": "now+96h"  
}  
}  
},  
{  
"bool": {  
"must": [  
{  
"match\_all": {}  
}  
]  
}  
}  
]  
}  
}  
}  
}  
}  
}  
}  
},  
"size": 0  
}'

and I get the partial result. Can I get the increment of the field 'record'  
during the time range? Thank you  
...  
{  
"time" : 1383264000000,  
"count" : 1059,  
"min" : 0.008,  
"max" : 12.607999999998452,  
"total" : 6771.335999999965,  
"total\_count" : 1059,  
"mean" : 6.3940849858356605  
}  
...

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [November 14, 2013, 10:28am UTC](https://discuss.elastic.co/t/scripting-in-date-histogram/14343/2 "2013-11-14T10:28:14Z")

</div>

Hey,

I dont understand what you mean with 'increment' in that context? Can you  
elaborate? What kind of information is missing exactly?

--Alex

On Mon, Nov 11, 2013 at 6:46 AM, 紫陈 [zixicc@gmail.com](mailto:zixicc@gmail.com) wrote:

> my curl request is  
> curl -XGET '[http://172.18.216.60:9200/resource/\_search?pretty](http://172.18.216.60:9200/resource/_search?pretty)' -d '{  
> "facets": {  
> "0": {  
> "date\_histogram": {  
> "key\_field": "timestamp",  
> "value\_script": "doc[\u0027record\u0027].value",  
> "interval": "12h"  
> },  
> "facet\_filter": {  
> "fquery": {  
> "query": {  
> "filtered": {  
> "query": {  
> "query\_string": {  
> "query": "01A"  
> }  
> },  
> "filter": {  
> "bool": {  
> "must": [  
> {  
> "match\_all": {}  
> },  
> {  
> "fquery": {  
> "query": {  
> "field": {  
> "bid": {  
> "query": ""110105C999""  
> }  
> }  
> },  
> "\_cache": true  
> }  
> },  
> {  
> "range": {  
> "timestamp": {  
> "from": 1380689917897,  
> "to": "now+96h"  
> }  
> }  
> },  
> {  
> "bool": {  
> "must": [  
> {  
> "match\_all": {}  
> }  
> ]  
> }  
> }  
> ]  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> },  
> "size": 0  
> }'
> 
> and I get the partial result. Can I get the increment of the field  
> 'record' during the time range? Thank you  
> ...  
> {  
> "time" : 1383264000000,  
> "count" : 1059,  
> "min" : 0.008,  
> "max" : 12.607999999998452,  
> "total" : 6771.335999999965,  
> "total\_count" : 1059,  
> "mean" : 6.3940849858356605  
> }  
> ...
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![11134](https://avatars.discourse-cdn.com/v4/letter/1/65b543/32.png) [@11134](https://discuss.elastic.co/u/11134)\
**Post date:** [November 15, 2013, 10:46am UTC](https://discuss.elastic.co/t/scripting-in-date-histogram/14343/3 "2013-11-15T10:46:27Z")

</div>

well, thanks.  
I mean that when it is timestamp1, the 'record' field's value is record1  
and when it is timestamp2, the 'record' field's value is record2  
timestamp2\>timestamp1, the increment is record2-record1, which means the  
change of the value  
if the field is just monotone increasing or decreasing, the increment can  
be (max-min) or (min-max).  
But if the field's value may increase or decrease, I don't know how to get  
the increment.  
By the way, does ES have other apis to get the 'increment'?  
在 2013年11月14日星期四UTC+8下午6时28分14秒，Alexander Reelsen写道：

> Hey,
> 
> I dont understand what you mean with 'increment' in that context? Can you  
> elaborate? What kind of information is missing exactly?
> 
> --Alex
> 
> On Mon, Nov 11, 2013 at 6:46 AM, 紫陈 \<[zix...@gmail.com](mailto:zix...@gmail.com) \<javascript:\>\>wrote:
> 
> > my curl request is  
> > curl -XGET '[http://172.18.216.60:9200/resource/\_search?pretty](http://172.18.216.60:9200/resource/_search?pretty)' -d '{  
> > "facets": {  
> > "0": {  
> > "date\_histogram": {  
> > "key\_field": "timestamp",  
> > "value\_script": "doc[\u0027record\u0027].value",  
> > "interval": "12h"  
> > },  
> > "facet\_filter": {  
> > "fquery": {  
> > "query": {  
> > "filtered": {  
> > "query": {  
> > "query\_string": {  
> > "query": "01A"  
> > }  
> > },  
> > "filter": {  
> > "bool": {  
> > "must": [  
> > {  
> > "match\_all": {}  
> > },  
> > {  
> > "fquery": {  
> > "query": {  
> > "field": {  
> > "bid": {  
> > "query": ""110105C999""  
> > }  
> > }  
> > },  
> > "\_cache": true  
> > }  
> > },  
> > {  
> > "range": {  
> > "timestamp": {  
> > "from": 1380689917897,  
> > "to": "now+96h"  
> > }  
> > }  
> > },  
> > {  
> > "bool": {  
> > "must": [  
> > {  
> > "match\_all": {}  
> > }  
> > ]  
> > }  
> > }  
> > ]  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > }  
> > },  
> > "size": 0  
> > }'
> > 
> > and I get the partial result. Can I get the increment of the field  
> > 'record' during the time range? Thank you  
> > ...  
> > {  
> > "time" : 1383264000000,  
> > "count" : 1059,  
> > "min" : 0.008,  
> > "max" : 12.607999999998452,  
> > "total" : 6771.335999999965,  
> > "total\_count" : 1059,  
> > "mean" : 6.3940849858356605  
> > }  
> > ...
> > 
> > --  
> > You received this message because you are subscribed to the Google Groups  
> > "elasticsearch" group.  
> > To unsubscribe from this group and stop receiving emails from it, send an  
> > email to [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:06am UTC](https://discuss.elastic.co/t/scripting-in-date-histogram/14343/4 "2017-07-06T02:06:46Z")

</div>


