# Date\_histogram with date range

**URL:** https://discuss.elastic.co/t/date-histogram-with-date-range/190450
**Category:** Elasticsearch
**Created:** [July 15, 2019, 7:46am UTC](https://discuss.elastic.co/t/date-histogram-with-date-range/190450 "2019-07-15T07:46:05Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![nitingarg](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@nitingarg](https://discuss.elastic.co/u/nitingarg)
#### Post date: [July 15, 2019, 7:46am UTC](https://discuss.elastic.co/t/date-histogram-with-date-range/190450/1 "2019-07-15T07:46:05Z")

</div>

I tried to use date histogram with specific range ,  
{  
"aggs": {  
"group\_by\_created\_ts": {  
"range": {  
"date\_histogram": {  
"field": "created\_ts",  
"interval": "day",  
"format": "yyyy-MM-dd",  
"ranges": [  
{  
"to": "2019-03-29"  
},  
{  
"from": "2019-02-29"  
}  
]  
}  
}  
}  
}  
}

it gives error  
"type": "x\_content\_parse\_exception",  
"reason": "[5:13] [range] unknown field [date\_histogram], parser not found"

---

<div class="post-metadata">

### Author: ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)
#### Post date: [July 15, 2019, 8:13am UTC](https://discuss.elastic.co/t/date-histogram-with-date-range/190450/2 "2019-07-15T08:13:51Z")

</div>

try this:

> ```
> {
> "query": {
> "range": {
> "snapTime": {
> "from": "2019-02-28",
> "to": "2019-03-29"
> }
> }
> },
> "aggs": {
> "group_by_created_ts": {
> "date_histogram": {
> "field": "created_ts",
> "interval": "day",
> "format": "yyyy-MM-dd"
> }
> }
> }
> }
> 
> ```

---

<div class="post-metadata">

### Author: ![nitingarg](https://avatars.discourse-cdn.com/v4/letter/n/53a042/32.png) [@nitingarg](https://discuss.elastic.co/u/nitingarg)
#### Post date: [July 15, 2019, 8:25am UTC](https://discuss.elastic.co/t/date-histogram-with-date-range/190450/3 "2019-07-15T08:25:56Z")

</div>

but if date type is text then how we run this

---

<div class="post-metadata">

### Author: ![wangqinghuan](https://avatars.discourse-cdn.com/v4/letter/w/d26b3c/32.png) [@wangqinghuan](https://discuss.elastic.co/u/wangqinghuan)
#### Post date: [July 16, 2019, 1:08am UTC](https://discuss.elastic.co/t/date-histogram-with-date-range/190450/4 "2019-07-16T01:08:13Z")

</div>

Why do you use text type? Date\_histogram is applied on numeric fields.

---

<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: [August 13, 2019, 1:08am UTC](https://discuss.elastic.co/t/date-histogram-with-date-range/190450/5 "2019-08-13T01:08:16Z")

</div>

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