# Best way to return different years in a ElasticSearch base

**URL:** https://discuss.elastic.co/t/best-way-to-return-different-years-in-a-elasticsearch-base/57019
**Category:** Elasticsearch
**Created:** [August 2, 2016, 2:20pm UTC](https://discuss.elastic.co/t/best-way-to-return-different-years-in-a-elasticsearch-base/57019 "2016-08-02T14:20:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![samuelr](https://avatars.discourse-cdn.com/v4/letter/s/9dc877/32.png) [@samuelr](https://discuss.elastic.co/u/samuelr)
#### Post date: [August 2, 2016, 2:20pm UTC](https://discuss.elastic.co/t/best-way-to-return-different-years-in-a-elasticsearch-base/57019/1 "2016-08-02T14:20:49Z")

</div>

I posted this question to find out if there is a better way to return  
years in a elasticsearch database, Without using aggregations.  
the kind of field is this:

```
{"type" : "date", "format": "dd-MM-yyyy HH:mm:ss"}

```

Note: I already can return the values using aggregations and date\_histogram. This way:

```
 GET _search
 { "size": 0,
    "aggs": {
        "group_by_doenca": {
            "date_histogram": {
                "field": "data",
                "interval" : "year",
                "format": "yyyy"

            }
        }
    }
} 

```

And is returning me correctly this:

```
"hits": {
"total": 100000000,
"max_score": 0,
"hits": []
},
"aggregations": {
 "group_by_date": {
 "buckets": [
    {
       "key_as_string": "1995",
       "key": 788918400000,
       "doc_count": 4547094
    },
    {
       "key_as_string": "1996",
       "key": 820454400000,
       "doc_count": 4543451
    },
    {
       "key_as_string": "1997",
       "key": 852076800000,
       "doc_count": 4547131
    }, 
  ....

```

As you can see, this base has 100kk of "lines" and the return time of this search of is about 5 seconds.

I need only the different years, do not need the doc\_count of these years.

So I wonder if there is how to modify this research, to be faster, and only return me the information I need?

Thank you so much

---

<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: [August 2, 2016, 2:42pm UTC](https://discuss.elastic.co/t/best-way-to-return-different-years-in-a-elasticsearch-base/57019/2 "2016-08-02T14:42:15Z")

</div>

Faster? I'm unsure. But may be it will reduce a bit the bandwidth if you use response filtering?

See [https://www.elastic.co/guide/en/elasticsearch/reference/2.3/common-options.html#\_response\_filtering](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/common-options.html#_response_filtering)

---

<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 5, 2017, 10:30pm UTC](https://discuss.elastic.co/t/best-way-to-return-different-years-in-a-elasticsearch-base/57019/3 "2017-07-05T22:30:43Z")

</div>


