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",
"PostId" : "http://www.abc.com/1234567890_542839079235084"
}, {
"@id" : "http://www.abc.com/1234567890_542839079235084",
"Language" : "http://www.xyz.com/ontology/Language/English ",
"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"
},
"PostDetails" : {
"@id" : "http://www.xyz.com/OWL/abc#PostDetails",
"@type" : "@id"
}
}
}
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"
}
}
}
}
}
}
}'
Response :
{"acknowledged":true}
Step 3 :
Indexing into ElasticSearch
curl -XPOST localhost:9200/facettest/data/1 -d @/home/bigtapp/Downloads/estestjson.json
Response :
{"_index":"facettest","_type":"data","_id":"1","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}
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",
"PostDetails" : "http://www.abc.com/1234567890_542839079235084",
"PostId" : "http://www.abc.com/1234567890_542839079235084"
}, {
"@id" : "http://www.abc.com/1234567890_542839079235084",
"Language" : "http://www.xyz.com/ontology/Language/English ",
"dbp" : [ "http://dbpedia.org/resource/Hypertext_Transfer_Protocol", "http://dbpedia.org/resource/Health_care" ],
"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"
},
"dbp" : {
"@id" : "http://www.xyz.com/ontology#dbp",
"@type" : "@id"
},
"PostDetails" : {
"@id" : "http://www.xyz.com/OWL/abc#PostDetails",
"@type" : "@id"
},
"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
#####################################
"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
} ]
}
}
}