# Not able to run aggregate query in ElasticSearch

**URL:** <https://discuss.elastic.co/t/not-able-to-run-aggregate-query-in-elasticsearch/60036>\
**Category:** Elasticsearch\
**Created:** [September 8, 2016, 4:28am UTC](https://discuss.elastic.co/t/not-able-to-run-aggregate-query-in-elasticsearch/60036 "2016-09-08T04:28:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SindhujaM](https://avatars.discourse-cdn.com/v4/letter/s/58f4c7/32.png) [@SindhujaM](https://discuss.elastic.co/u/SindhujaM)\
**Post date:** [September 8, 2016, 4:28am UTC](https://discuss.elastic.co/t/not-able-to-run-aggregate-query-in-elasticsearch/60036/1 "2016-09-08T04:28:15Z")

</div>

PROBLEM :

Version : ElasticSearch 2.4.0

Not able to run aggregate(Facets) query for a nested JsonLD.

Step 1 :

Input JSonLD File

{  
"@graph" : [ {  
"@id" : "[http://www.xyz.com/ontology/Person/estate](http://www.xyz.com/ontology/Person/estate)",  
"Gender" : "[http://www.xyz.com/ontology/Gender/Female](http://www.xyz.com/ontology/Gender/Female)"  
}, {  
"@id" : "[http://www.abc.com/1234567890](http://www.abc.com/1234567890)",  
"PageId" : "1234567890",  
"PostId" : "[http://www.abc.com/1234567890\_542839079235084](http://www.abc.com/1234567890_542839079235084)"  
}, {  
"@id" : "[http://www.abc.com/1234567890\_542839079235084](http://www.abc.com/1234567890_542839079235084)",  
"[http://www.xyz.com/OWL/abc#CategoryName](http://www.xyz.com/OWL/abc#CategoryName)" : "Real Estate"  
} ],  
"@context" : {  
"Gender" : {  
"@id" : "[http://www.xyz.com/ontology#Gender](http://www.xyz.com/ontology#Gender)",  
"@type" : "@id"  
},  
"CategoryName" : {  
"@id" : "[http://www.xyz.com/OWL/abc#CategoryName](http://www.xyz.com/OWL/abc#CategoryName)",  
"@type" : "[http://www.w3.org/2001/XMLSchema#string](http://www.w3.org/2001/XMLSchema#string)"  
},  
"PostId" : "[http://www.xyz.com/OWL/abc#PostId](http://www.xyz.com/OWL/abc#PostId)",  
"PageId" : "[http://www.xyz.com/OWL/abc#PageId](http://www.xyz.com/OWL/abc#PageId)"  
}  
}

Step 2 :

Mapping

curl -XPOST localhost:9200/facettest -d '{  
"mappings": {  
"data": {  
"properties": {  
"[http://www.xyz.com/OWL/abc#CategoryName](http://www.xyz.com/OWL/abc#CategoryName)" : {  
"type": "string",  
"fields": {  
"raw" : {  
"type": "string",  
"index": "not\_analyzed"  
}  
}  
}  
}  
}  
}  
}'

Step 3 :

Indexing into ElasticSearch

curl -XPOST localhost:9200/facettest/data/1 -d @/home/bigtapp/Downloads/estestjson.json

Step 4 :

curl -XGET localhost:9200/facettest/data/\_search/?pretty=true -d '{  
"size" : 10,  
"aggs" : {  
"[http://www.xyz.com/OWL/abc#CategoryName](http://www.xyz.com/OWL/abc#CategoryName)" : {  
"terms" : {  
"field" : "[http://www.xyz.com/OWL/abc#CategoryName.raw](http://www.xyz.com/OWL/abc#CategoryName.raw)"  
}  
}  
}  
}'

Response :

{  
"took" : 8,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "facettest",  
"\_type" : "data",  
"\_id" : "1",  
"\_score" : 1.0,  
"\_source" : {  
"@graph" : [ {  
"@id" : "[http://www.xyz.com/ontology/Person/estate](http://www.xyz.com/ontology/Person/estate)",  
"Gender" : "[http://www.xyz.com/ontology/Gender/Female](http://www.xyz.com/ontology/Gender/Female)"  
}, {  
"@id" : "[http://www.abc.com/1234567890](http://www.abc.com/1234567890)",  
"PageId" : "1234567890",  
"PostId" : "[http://www.abc.com/1234567890\_542839079235084](http://www.abc.com/1234567890_542839079235084)"  
}, {  
"@id" : "[http://www.abc.com/1234567890\_542839079235084](http://www.abc.com/1234567890_542839079235084)",  
"[http://www.xyz.com/OWL/abc#CategoryName](http://www.xyz.com/OWL/abc#CategoryName)" : "Real Estate"  
} ],  
"@context" : {  
"Gender" : {  
"@id" : "[http://www.xyz.com/ontology#Gender](http://www.xyz.com/ontology#Gender)",  
"@type" : "@id"  
},  
"CategoryName" : {  
"@id" : "[http://www.xyz.com/OWL/abc#CategoryName](http://www.xyz.com/OWL/abc#CategoryName)",  
"@type" : "[http://www.w3.org/2001/XMLSchema#string](http://www.w3.org/2001/XMLSchema#string)"  
},  
"PostId" : "[http://www.xyz.com/OWL/abc#PostId](http://www.xyz.com/OWL/abc#PostId)",  
"PageId" : "[http://www.xyz.com/OWL/abc#PageId](http://www.xyz.com/OWL/abc#PageId)"  
}  
}  
} ]  
},  
"aggregations" : {  
"[http://www.xyz.com/OWL/abc#CategoryName](http://www.xyz.com/OWL/abc#CategoryName)" : {  
"doc\_count\_error\_upper\_bound" : 0,  
"sum\_other\_doc\_count" : 0,  
"buckets" : []  
}  
}  
}

* * *

Here, we dont get any aggregation for the CategoryName

* * *

Expected Result in Aggregation  
#####################################  
{  
"took" : 8,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 1,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "facettest",  
"\_type" : "data",  
"\_id" : "1",  
"\_score" : 1.0,  
"\_source" : {  
"@graph" : [ {  
"@id" : "[http://www.xyz.com/ontology/Person/estate](http://www.xyz.com/ontology/Person/estate)",  
"Gender" : "[http://www.xyz.com/ontology/Gender/Female](http://www.xyz.com/ontology/Gender/Female)"  
}, {  
"@id" : "[http://www.abc.com/1234567890](http://www.abc.com/1234567890)",  
"PageId" : "1234567890",  
"PostId" : "[http://www.abc.com/1234567890\_542839079235084](http://www.abc.com/1234567890_542839079235084)"  
}, {  
"@id" : "[http://www.abc.com/1234567890\_542839079235084](http://www.abc.com/1234567890_542839079235084)"  
"[http://www.xyz.com/OWL/abc#CategoryName](http://www.xyz.com/OWL/abc#CategoryName)" : "Real Estate"  
} ],  
"@context" : {  
"Gender" : {  
"@id" : "[http://www.xyz.com/ontology#Gender](http://www.xyz.com/ontology#Gender)",  
"@type" : "@id"  
},  
"CategoryName" : {  
"@id" : "[http://www.xyz.com/OWL/abc#CategoryName](http://www.xyz.com/OWL/abc#CategoryName)",  
"@type" : "[http://www.w3.org/2001/XMLSchema#string](http://www.w3.org/2001/XMLSchema#string)"  
},  
"PostId" : "[http://www.xyz.com/OWL/abc#PostId](http://www.xyz.com/OWL/abc#PostId)",  
"PageId" : "[http://www.xyz.com/OWL/abc#PageId](http://www.xyz.com/OWL/abc#PageId)"  
}  
}  
} ]  
},  
"aggregations" : {  
"[http://www.xyz.com/OWL/abc#CategoryName](http://www.xyz.com/OWL/abc#CategoryName)" : {  
"doc\_count\_error\_upper\_bound" : 0,  
"sum\_other\_doc\_count" : 0,  
"buckets" : [  
{  
"Key" : "Real Estate",  
"doc\_count" : 1  
} ]  
}  
}  
}

---

<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:** [September 8, 2016, 8:54am UTC](https://discuss.elastic.co/t/not-able-to-run-aggregate-query-in-elasticsearch/60036/2 "2016-09-08T08:54:26Z")

</div>

Please do not post duplicate topics.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 8, 2016, 8:57am UTC](https://discuss.elastic.co/t/not-able-to-run-aggregate-query-in-elasticsearch/60036/3 "2016-09-08T08:57:21Z")

</div>

> [@Not able to run aggregate(Facets) query for a nested JsonLD](https://discuss.elastic.co/t/not-able-to-run-aggregate-facets-query-for-a-nested-jsonld/59976):
>
> PROBLEM : Version : ElasticSearch 2.4.0 Not able to run aggregate(Facets) query for a nested JsonLD. Step 1 :Input JSonLD File { "@graph" : [{ "@id" : "[http://www.xyz.com/ontology/Person/estate](http://www.xyz.com/ontology/Person/estate)", "Gender" : "[http://www.xyz.com/ontology/Gender/Female](http://www.xyz.com/ontology/Gender/Female)" }, { "@id" : "[http://www.abc.com/1234567890](http://www.abc.com/1234567890)", "PostId" : "[http://www.abc.com/1234567890\_542839079235084](http://www.abc.com/1234567890_542839079235084)" }, { "@id" : "[http://www.abc.com/1234567890\_542839079235084](http://www.abc.com/1234567890_542839079235084)", "Language" : "[http://www.xyz.com/ontology/Language/English](http://www.xyz.com/ontology/Language/English) ", "[http…](http://www.xyz.com/OWL/abc#CategoryName)

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [September 8, 2016, 8:57am UTC](https://discuss.elastic.co/t/not-able-to-run-aggregate-query-in-elasticsearch/60036/4 "2016-09-08T08:57:24Z")

</div>


