Skip to content

Instantly share code, notes, and snippets.

@rubish
Created November 11, 2011 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rubish/1357430 to your computer and use it in GitHub Desktop.
Save rubish/1357430 to your computer and use it in GitHub Desktop.
elasticsearch nested facets problem
{
"user":{
"properties":{
"profile_completeness":{ "type":"double" },
"created_at":{ "format":"dateOptionalTime", "type":"date" },
"user_type":{ "type":"string" },
"professions":{
"type":"nested",
"properties":{
"to":{ "format":"dateOptionalTime", "type":"date" },
"_id":{ "type":"string" },
"description":{ "type":"string" },
"department":{ "type":"string" },
"designation":{ "type":"string" },
"current":{ "type":"boolean" },
"from":{ "format":"dateOptionalTime", "type":"date" },
"company_site":{ "type":"string" },
"location_id":{ "type":"string" },
"company":{
"type":"multi_field",
"fields":{
"lower":{ "include_in_all":false, "analyzer":"lower_keyword", "boost":20.0, "type":"string" },
"company":{ "analyzer":"name_analyzer", "boost":10.0, "type":"string" },
"untouched":{ "include_in_all":false, "index":"not_analyzed", "store":"yes", "type":"string" }
}
}
}
},
"college_id":{ "type":"string" },
"invitation_token":{ "type":"string" },
"alma_info":{
"properties":{
"course":{ "index":"not_analyzed", "store":"yes", "type":"string" },
"rollno":{ "type":"string" },
"_id":{ "type":"string" },
"department":{ "type":"string" },
"designation":{ "type":"string" },
"branch":{ "index":"not_analyzed", "type":"string" },
"discipline":{ "index":"not_analyzed", "store":"yes", "type":"string" },
"joining_year":{ "type":"integer" },
"graduation_year":{ "type":"integer" }
}
},
"personal_info":{
"properties":{
"title":{ "index":"no", "type":"string" },
"lname":{ "type":"string" },
"anniversary":{ "format":"dateOptionalTime", "type":"date" },
"married":{ "type":"boolean" },
"_id":{ "type":"string" },
"dob":{ "format":"dateOptionalTime", "type":"date" },
"gender":{ "type":"string" },
"fname":{ "type":"string" },
"name":{
"type":"multi_field",
"fields":{
"lower":{ "include_in_all":false, "analyzer":"lower_keyword", "boost":20.0, "type":"string" },
"name":{ "store":"yes", "analyzer":"name_analyzer", "boost":10.0, "type":"string" },
"untouched":{ "include_in_all":false, "index":"not_analyzed", "store":"yes", "type":"string" }
}
}
}
}
}
}
}
curl -X GET "http://localhost:9200/development_users/user/_search?pretty=true" -d '
{
"query":{
"bool":{
"must":[
{
"term":{
"college_id":"4eb8f0f575f38e461700000c"
}
},
{
"terms":{
"user_type":[
"alumni",
"faculty",
"student"
]
}
}
]
}
},
"sort":[
{
"profile_completeness":"desc"
},
{
"created_at":"asc"
}
],
"facets":{
"companies":{
"terms":{
"field":"professions.company",
"size":50,
"all_terms":false,
"nested":"professions"
}
}
},
"size":0,
"from":0
}
'
# output
{
"took" : 8,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 1483,
"max_score" : null,
"hits" : [ ]
},
"facets" : {
"companies" : {
"_type" : "terms",
"missing" : 1483,
"total" : 0,
"other" : 0,
"terms" : [ ]
}
}
}
curl -X GET "http://localhost:9200/development_users/user/_search?pretty=true" -d '
{
"query":{
"bool":{
"must":[
{
"term":{
"college_id":"4eb8f0f575f38e461700000c"
}
},
{
"terms":{
"user_type":[
"alumni",
"faculty",
"student"
]
}
}
]
},
"nested":{
"path":"professions",
"_scope":"company",
"query":{
"bool":{
"must":[
{
"term":{
"professions.company":"adobe"
}
}
]
}
}
}
},
"sort":[
{
"profile_completeness":"desc"
},
{
"created_at":"asc"
}
],
"facets":{
"companies":{
"terms":{
"field":"professions.company",
"size":50,
"all_terms":false,
"scope":"company"
}
}
},
"size":0,
"from":0
}
'
#output
{
"error" : "SearchPhaseExecutionException[Failed to execute phase [query_fetch], total failure; shardFailures {[dp29GzyfRnqaYyd2SNqQow][development_users][0]: SearchParseException[[development_users][0]: query[+college_id:4eb8f0f575f38e461700000c +((user_type:alumni user_type:faculty user_type:student)~1)],from[-1],size[-1]: Parse Failure [Failed to parse source [{\"query\":{\"bool\":{\"must\":[{\"term\":{\"college_id\":\"4eb8f0f575f38e461700000c\"}},{\"terms\":{\"user_type\":[\"alumni\",\"faculty\",\"student\"]}}]},\"nested\":{\"path\":\"professions\",\"_scope\":\"company\",\"query\":{\"bool\":{\"must\":[{\"term\":{\"professions.company\":\"adobe\"}}]}}}},\"sort\":[{\"profile_completeness\":\"desc\"},{\"created_at\":\"asc\"}],\"facets\":{\"companies\":{\"terms\":{\"field\":\"professions.company\",\"size\":50,\"all_terms\":false,\"scope\":\"company\"}}},\"size\":0,\"from\":0}]]]; nested: SearchParseException[[development_users][0]: query[+college_id:4eb8f0f575f38e461700000c +((user_type:alumni user_type:faculty user_type:student)~1)],from[-1],size[-1]: Parse Failure [No parser for element [path]]]; }]",
"status" : 500
}
{
"_id":"4eb8f6a475f38e4bc100172a",
"_type":"User",
"alma_info":{
"_id":"4eb8f6a475f38e4bc1001729",
"branch":"ECE",
"course":"M.Tech.",
"graduation_year":2011,
"joining_year":2009,
"rollno":"MV9548-6629",
"discipline":"M.Tech. - ECE"
},
"college_id":"4eb8f0f575f38e461700000c",
"experience":2.1416666666666666,
"personal_info":{
"_id":"4eb8f6a475f38e4bc1001728",
"anniversary":"2005-08-26T00:00:00+05:30",
"dob":"1981-03-20T00:00:00+05:30",
"fname":"Ethyl",
"gender":"M",
"lname":"Collier",
"married":true,
"title":"Mrs.",
"name":"Mrs. Ethyl Collier",
"hometown_string":null,
"current_city_string":null
},
"professions":[
{
"current":true,
"company":"Alma Connect",
"from":"2011-01-31T18:30:00Z",
"to":null,
"designation":"CoFounder",
"department":"Technology",
"company_site":"http://www.almaconnect.com/",
"location_id":"7279746",
"description":"",
"_id":"4ebb814b75f38e289900002f"
},
{
"current":false,
"company":"Joshlabs",
"from":"2009-09-30T18:30:00Z",
"to":"2011-01-31T18:30:00Z",
"designation":"Senior Developer",
"department":"Technology",
"company_site":"http://joshlabs.in/",
"location_id":"1270642",
"description":"",
"_id":"4ebb814b75f38e2899000030"
}
],
"profile_completeness":26.136363636363637,
"user_type":"student"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment