Not able to run aggregate query in ElasticSearch


(Sindhuja Muthukumar) #1

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",
"Gender" : "http://www.xyz.com/ontology/Gender/Female"
}, {
"@id" : "http://www.abc.com/1234567890",
"PageId" : "1234567890",
"PostId" : "http://www.abc.com/1234567890_542839079235084"
}, {
"@id" : "http://www.abc.com/1234567890_542839079235084",
"http://www.xyz.com/OWL/abc#CategoryName" : "Real Estate"
} ],
"@context" : {
"Gender" : {
"@id" : "http://www.xyz.com/ontology#Gender",
"@type" : "@id"
},
"CategoryName" : {
"@id" : "http://www.xyz.com/OWL/abc#CategoryName",
"@type" : "http://www.w3.org/2001/XMLSchema#string"
},
"PostId" : "http://www.xyz.com/OWL/abc#PostId",
"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" : {
"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" : {
"terms" : {
"field" : "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",
"Gender" : "http://www.xyz.com/ontology/Gender/Female"
}, {
"@id" : "http://www.abc.com/1234567890",
"PageId" : "1234567890",
"PostId" : "http://www.abc.com/1234567890_542839079235084"
}, {
"@id" : "http://www.abc.com/1234567890_542839079235084",
"http://www.xyz.com/OWL/abc#CategoryName" : "Real Estate"
} ],
"@context" : {
"Gender" : {
"@id" : "http://www.xyz.com/ontology#Gender",
"@type" : "@id"
},
"CategoryName" : {
"@id" : "http://www.xyz.com/OWL/abc#CategoryName",
"@type" : "http://www.w3.org/2001/XMLSchema#string"
},
"PostId" : "http://www.xyz.com/OWL/abc#PostId",
"PageId" : "http://www.xyz.com/OWL/abc#PageId"
}
}
} ]
},
"aggregations" : {
"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",
"Gender" : "http://www.xyz.com/ontology/Gender/Female"
}, {
"@id" : "http://www.abc.com/1234567890",
"PageId" : "1234567890",
"PostId" : "http://www.abc.com/1234567890_542839079235084"
}, {
"@id" : "http://www.abc.com/1234567890_542839079235084"
"http://www.xyz.com/OWL/abc#CategoryName" : "Real Estate"
} ],
"@context" : {
"Gender" : {
"@id" : "http://www.xyz.com/ontology#Gender",
"@type" : "@id"
},
"CategoryName" : {
"@id" : "http://www.xyz.com/OWL/abc#CategoryName",
"@type" : "http://www.w3.org/2001/XMLSchema#string"
},
"PostId" : "http://www.xyz.com/OWL/abc#PostId",
"PageId" : "http://www.xyz.com/OWL/abc#PageId"
}
}
} ]
},
"aggregations" : {
"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
} ]
}
}
}


(Mark Harwood) #2

Please do not post duplicate topics.


(Mark Walkom) #3

(Mark Walkom) #4