# Stats or Date Histogram query for unindexed fields

**URL:** <https://discuss.elastic.co/t/stats-or-date-histogram-query-for-unindexed-fields/20073>\
**Category:** Elasticsearch\
**Created:** [October 4, 2014, 2:25am UTC](https://discuss.elastic.co/t/stats-or-date-histogram-query-for-unindexed-fields/20073 "2014-10-04T02:25:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abid\_mahmood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abid_mahmood/32/1232_2.png) [@abid\_mahmood](https://discuss.elastic.co/u/abid_mahmood)\
**Post date:** [October 4, 2014, 2:25am UTC](https://discuss.elastic.co/t/stats-or-date-histogram-query-for-unindexed-fields/20073/1 "2014-10-04T02:25:28Z")

</div>

ElasticSearch Newbee so kindly consider stupid questions 😉

lets say I have the following document structure

{  
"@timestamp": DDMMYYHHMMSS,  
"title": "some test here",  
"views": 4  
}

and my mapping is

mappings: {

- 
  - 

_default_: {  
- -  
\_all: {  
- enabled: false  
}  
}

- 
  - 

mytype: {  
- dynamic: "strict"  
- -  
\_all: {  
- enabled: false  
}  
- -  
properties: {  
- -  
@timestamp: {  
- type: "date"  
- format: "dateOptionalTime"  
}  
- -  
_title_: {  
- type: "string"  
}  
- -  
- -  
views: {  
- type: "integer"  
- index: "no"  
}  
}  
}

}

so basically I don't want to index my views field as I don't want to search  
by views, but I want to get stats for this field or get a date histogram,  
for example a histogram of the total views over a given time per hour or  
per day

my query looks like this  
{  
"facets": {  
"0": {  
"date\_histogram": {  
"key\_field": "@timestamp",  
"value\_field": "views",  
"interval": "1y"  
},  
"global": true,  
"facet\_filter": {  
"fquery": {  
"query": {  
"filtered": {  
"query": {  
"query\_string": {  
"query": "\*"  
}  
},  
"filter": {  
"bool": {  
"must": [  
{  
"match\_all": {}  
}  
]  
}  
}  
}  
}  
}  
}  
}  
},  
"size": 0  
}

this returns

facets: {

- 
  - 

0: {  
- \_type: "date\_histogram"  
- -  
entries: [  
- -  
{  
- time: 1356998400000  
- count: 27339  
- min: "Infinity"  
- max: "-Infinity"  
- total: 0  
- total\_count: 0  
- mean: 0  
}  
]  
}

}

so my question is can I do facet/aggregation querries on fields that are  
not indexed ? and if not why not ? isn't indexing supposed to be only for  
searching ?

Thanks

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/75539648-c132-4e70-bb72-bb49c6c4e7db%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/75539648-c132-4e70-bb72-bb49c6c4e7db%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [October 4, 2014, 3:09am UTC](https://discuss.elastic.co/t/stats-or-date-histogram-query-for-unindexed-fields/20073/2 "2014-10-04T03:09:38Z")

</div>

No. You need to index fields of you want to search and compute on those fields.

> Le 4 oct. 2014 à 04:25, abid mahmood [mabid.mahmood@gmail.com](mailto:mabid.mahmood@gmail.com) a écrit :
> 
> Elasticsearch Newbee so kindly consider stupid questions 😉
> 
> lets say I have the following document structure
> 
> {  
> "@timestamp": DDMMYYHHMMSS,  
> "title": "some test here",  
> "views": 4  
> }
> 
> and my mapping is
> 
> ## mappings: { -_default_: { -\_all: { enabled: false } } -mytype: { dynamic: "strict" -\_all: { enabled: false } -properties: { -@timestamp: { type: "date" format: "dateOptionalTime" } -title: { type: "string" }
> 
> -views: {  
> type: "integer"  
> index: "no"  
> }  
> }  
> }  
> }
> 
> so basically I don't want to index my views field as I don't want to search by views, but I want to get stats for this field or get a date histogram, for example a histogram of the total views over a given time per hour or per day
> 
> my query looks like this  
> {  
> "facets": {  
> "0": {  
> "date\_histogram": {  
> "key\_field": "@timestamp",  
> "value\_field": "views",  
> "interval": "1y"  
> },  
> "global": true,  
> "facet\_filter": {  
> "fquery": {  
> "query": {  
> "filtered": {  
> "query": {  
> "query\_string": {  
> "query": "\*"  
> }  
> },  
> "filter": {  
> "bool": {  
> "must": [  
> {  
> "match\_all": {}  
> }  
> ]  
> }  
> }  
> }  
> }  
> }  
> }  
> }  
> },  
> "size": 0  
> }
> 
> this returns
> 
> facets: {  
> -0: {  
> \_type: "date\_histogram"  
> -entries: [  
> -{  
> time: 1356998400000  
> count: 27339  
> min: "Infinity"  
> max: "-Infinity"  
> total: 0  
> total\_count: 0  
> mean: 0  
> }  
> ]  
> }  
> }
> 
> so my question is can I do facet/aggregation querries on fields that are not indexed ? and if not why not ? isn't indexing supposed to be only for searching ?
> 
> ## Thanks
> 
> 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).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/75539648-c132-4e70-bb72-bb49c6c4e7db%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/75539648-c132-4e70-bb72-bb49c6c4e7db%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/B758608D-B8B8-4F69-8AA5-E5C469E95C6F%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/B758608D-B8B8-4F69-8AA5-E5C469E95C6F%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:58am UTC](https://discuss.elastic.co/t/stats-or-date-histogram-query-for-unindexed-fields/20073/3 "2017-07-06T00:58:17Z")

</div>


