# Group by condition specify type

**URL:** <https://discuss.elastic.co/t/group-by-condition-specify-type/124890>\
**Category:** Elasticsearch\
**Created:** [March 21, 2018, 2:40am UTC](https://discuss.elastic.co/t/group-by-condition-specify-type/124890 "2018-03-21T02:40:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill\_Villa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bill_villa/32/29064_2.png) [@Bill\_Villa](https://discuss.elastic.co/u/Bill_Villa)\
**Post date:** [March 21, 2018, 2:40am UTC](https://discuss.elastic.co/t/group-by-condition-specify-type/124890/1 "2018-03-21T02:40:22Z")

</div>

I'm trying to aggregation tag by specify type such type = 1 and type =2 . But it's not working ???  
curl -XDELETE 'localhost:9200/employ'  
curl -XPUT 'localhost:9200/employ?pretty' -H 'Content-Type: application/json' -d'  
{  
"mappings": {  
"info": {  
"properties": {  
"name": { "type": "text", "fielddata": true},  
"age": { "type": "text", "fielddata": true},  
"tag": {  
"properties" : {  
"attribute" : {"type" : "text", "fielddata": true},  
"type" : {"type" : "text", "fielddata": true}  
}  
}  
}  
}  
}  
}  
'  
curl -XPUT 'localhost:9200/employ/info/1?refresh&pretty' -H 'Content-Type: application/json' -d'  
{  
"name": "hungokata",  
"age" : 20,  
"tag": [  
{  
"attribute" : 1,  
"type": 1  
},  
{  
"attribute": 2,  
"type":2  
},  
{  
"attribute": 3,  
"type":2  
}  
]  
}  
'

curl -XPUT 'localhost:9200/employ/info/2?refresh&pretty' -H 'Content-Type: application/json' -d'  
{  
"name": "hungokata 123",  
"age" : 21,  
"tag": [  
{  
"attribute": 1,  
"type": 1  
},  
{  
"attribute": 2,  
"type": 2  
}  
]  
}  
'

curl -XPUT 'localhost:9200/employ/info/3?refresh&pretty' -H 'Content-Type: application/json' -d'  
{  
"name": "hungokata",  
"age" : 22,  
"tag": [  
{  
"attribute" : 1,  
"type": 1  
},  
{  
"attribute" : 2,  
"type": 2  
}  
]  
}  
'

=\>\>\> Expect But It's not working

curl -XGET 'localhost:9200/employ/\_search?pretty' -H 'Content-Type: application/json' -d'  
{  
"size":0,  
"aggs": {  
"groupby\_attribute\_1": {  
"filter" : {  
"term" : {  
"tag.type" : "1"  
}  
},  
"aggs": {  
"terms": {  
"field": "tag.attribute"  
}  
}  
},  
"groupby\_attribute\_2": {  
"filter" : {  
"term" : {  
"tag.type" : "2"  
}  
},  
"aggs": {  
"terms": {  
"field": "tag.attribute"  
}  
}  
}  
}  
}'

---

<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:** [April 18, 2018, 2:40am UTC](https://discuss.elastic.co/t/group-by-condition-specify-type/124890/2 "2018-04-18T02:40:38Z")

</div>

Closed on April 18, 2018, 2:40am UTC

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