# I want to return only terms of a field

**URL:** <https://discuss.elastic.co/t/i-want-to-return-only-terms-of-a-field/205445>\
**Category:** Elasticsearch\
**Created:** [October 28, 2019, 11:00am UTC](https://discuss.elastic.co/t/i-want-to-return-only-terms-of-a-field/205445 "2019-10-28T11:00:49Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dinesh\_c](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_c/32/56700_2.png) [@dinesh\_c](https://discuss.elastic.co/u/dinesh_c)\
**Post date:** [October 28, 2019, 11:00am UTC](https://discuss.elastic.co/t/i-want-to-return-only-terms-of-a-field/205445/1 "2019-10-28T11:00:49Z")

</div>

By using terms aggregation I am getting terms as well as doct count but i need only terms is there a way to get only terms.

this is the default response

```auto
    ...

    "aggregations" : {
        "genres" : {
            "doc_count_error_upper_bound": 0, 
            "sum_other_doc_count": 0, 
            "buckets" : [ 
                {
                    "key" : "jazz",
                    "doc_count" : 10
                },
                {
                    "key" : "rock",
                    "doc_count" : 10
                },
                {
                    "key" : "electronic",
                    "doc_count" : 10
                },
            ]
        }
    }
}

```

But i need

```auto
{
	"aggregations": {
		"genres": {
			"keys": [
				"jazz",
				"rock",
				"electronic"
			]
		}
	}
}

```

---

<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:** [October 31, 2019, 1:11pm UTC](https://discuss.elastic.co/t/i-want-to-return-only-terms-of-a-field/205445/2 "2019-10-31T13:11:57Z")

</div>

you could use the [filter\_path parameter](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/common-options.html#common-options-response-filtering) - however the numbers would still be calculated though, just omitted in the response. You can however not change the response.

---

<div class="post-metadata">

**Author:** ![dinesh\_c](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_c/32/56700_2.png) [@dinesh\_c](https://discuss.elastic.co/u/dinesh_c)\
**Post date:** [October 31, 2019, 4:50pm UTC](https://discuss.elastic.co/t/i-want-to-return-only-terms-of-a-field/205445/3 "2019-10-31T16:50:49Z")

</div>

I do not understand how to use filter path to get the required response. Can you please explain?

---

<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 4, 2019, 9:53am UTC](https://discuss.elastic.co/t/i-want-to-return-only-terms-of-a-field/205445/4 "2019-11-04T09:53:26Z")

</div>

you could filter on `aggregations.genres.buckets.**.key` and see if that works to only extract the keys. You cannot modify the JSON though.

---

<div class="post-metadata">

**Author:** ![dinesh\_c](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_c/32/56700_2.png) [@dinesh\_c](https://discuss.elastic.co/u/dinesh_c)\
**Post date:** [November 5, 2019, 8:10am UTC](https://discuss.elastic.co/t/i-want-to-return-only-terms-of-a-field/205445/5 "2019-11-05T08:10:16Z")

</div>

Thanks for your reply, now I understand your previous comments also.Can you please tell me is there a way not to calculate the docs\_count.

---

<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 5, 2019, 9:37am UTC](https://discuss.elastic.co/t/i-want-to-return-only-terms-of-a-field/205445/6 "2019-11-05T09:37:50Z")

</div>

The `doc_count` is always calculated, unless another metric aggregation is specified.

---

<div class="post-metadata">

**Author:** ![dinesh\_c](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_c/32/56700_2.png) [@dinesh\_c](https://discuss.elastic.co/u/dinesh_c)\
**Post date:** [November 5, 2019, 10:21am UTC](https://discuss.elastic.co/t/i-want-to-return-only-terms-of-a-field/205445/7 "2019-11-05T10:21:46Z")

</div>

Hi @spinscale,

thanks for your quick reply can you give an example how to pass another metric.

---

<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 5, 2019, 10:22am UTC](https://discuss.elastic.co/t/i-want-to-return-only-terms-of-a-field/205445/8 "2019-11-05T10:22:21Z")

</div>

See [https://www.elastic.co/guide/en/elasticsearch/reference/7.4/search-aggregations-metrics.html](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/search-aggregations-metrics.html)

---

<div class="post-metadata">

**Author:** ![dinesh\_c](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dinesh_c/32/56700_2.png) [@dinesh\_c](https://discuss.elastic.co/u/dinesh_c)\
**Post date:** [November 5, 2019, 10:52am UTC](https://discuss.elastic.co/t/i-want-to-return-only-terms-of-a-field/205445/9 "2019-11-05T10:52:23Z")

</div>

There is no java api for filter\_path. Isn't it?

---

<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 6, 2019, 8:56am UTC](https://discuss.elastic.co/t/i-want-to-return-only-terms-of-a-field/205445/10 "2019-11-06T08:56:09Z")

</div>

you can add it as a parameter, but I would refrain from that using the High Level Rest Client

See [https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.4/java-rest-low-usage-requests.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/7.4/java-rest-low-usage-requests.html)

---

<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:** [December 4, 2019, 8:59am UTC](https://discuss.elastic.co/t/i-want-to-return-only-terms-of-a-field/205445/11 "2019-12-04T08:59:49Z")

</div>

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