# Querying array types

**URL:** <https://discuss.elastic.co/t/querying-array-types/32808>\
**Category:** Elasticsearch\
**Created:** [October 22, 2015, 9:46pm UTC](https://discuss.elastic.co/t/querying-array-types/32808 "2015-10-22T21:46:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mramaprasad](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@mramaprasad](https://discuss.elastic.co/u/mramaprasad)\
**Post date:** [October 22, 2015, 9:46pm UTC](https://discuss.elastic.co/t/querying-array-types/32808/1 "2015-10-22T21:46:23Z")

</div>

I have category as array type.  
I need to get all the distinct categories.  
"software",  
"development",  
"cloud computing",  
"project management"

What kind query should I use?

curl -XPUT '[http://localhost:9200/cstest/csproducts/1](http://localhost:9200/cstest/csproducts/1)' -d '  
{  
"productid":"1",  
"productnumber":"123",  
"category":["software"]  
}

curl -XPUT '[http://localhost:9200/test/products/2](http://localhost:9200/test/products/2)' -d '  
{  
"productid":"2",  
"productnumber":"1234",  
"category":["software","development"]  
}

curl -XPUT '[http://localhost:9200/test/products/3](http://localhost:9200/test/products/3)' -d '  
{  
"productid":"2",  
"productnumber":"1234",  
"category":["cloud computing","project management"]  
}

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [October 23, 2015, 8:22am UTC](https://discuss.elastic.co/t/querying-array-types/32808/2 "2015-10-23T08:22:45Z")

</div>

Here is a search that returns zero docs but the top 100 category terms:

```
GET /test/csproducts/_search
{
	"size":0,
	"aggs":{
		"allCategories":{
			"terms":{
				"field":"category",
				"size":100
			}
		}
	}
}
```

---

<div class="post-metadata">

**Author:** ![mramaprasad](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@mramaprasad](https://discuss.elastic.co/u/mramaprasad)\
**Post date:** [October 23, 2015, 7:20pm UTC](https://discuss.elastic.co/t/querying-array-types/32808/3 "2015-10-23T19:20:35Z")

</div>

Thanks for the reply.  
When the category is "cloud computing"  
It is being considered as a two different categories.

It returns something like -  
"aggregations" : {  
"allCategories" : {  
"buckets" : [ {  
"key" : "software",  
"doc\_count" : 2  
}, {  
"key" : "cloud",  
"doc\_count" : 1  
}, {  
"key" : "computing",  
"doc\_count" : 1  
}, {  
"key" : "development",  
"doc\_count" : 1  
}, {  
"key" : "management",  
"doc\_count" : 1  
}, {  
"key" : "project",  
"doc\_count" : 1  
} ]  
}  
}

I tried adding "position\_offset\_gap": 100, but did not help.

---

<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, 11:42pm UTC](https://discuss.elastic.co/t/querying-array-types/32808/4 "2017-07-05T23:42:53Z")

</div>


