Skip to content

Instantly share code, notes, and snippets.

@rubish
Created November 14, 2011 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubish/1363521 to your computer and use it in GitHub Desktop.
Save rubish/1363521 to your computer and use it in GitHub Desktop.
ArrayIndexOutOfBound for ES nested facets
curl -X DELETE "http://localhost:9200/test_users"
curl -X POST "http://localhost:9200/test_users" -d '
{
"mappings":{
"user":{
"properties":{
"email":{ "index":"no", "type":"string" },
"alma_info":{
"type":"object",
"properties":{
"joining_year":{ "type":"integer" },
"graduation_year":{ "type":"integer" },
"branch":{ "index":"not_analyzed", "type":"string" },
"course":{ "index":"not_analyzed", "store":true, "type":"string" },
"discipline":{ "index":"not_analyzed", "store":true, "type":"string" },
"rollno":{ "type":"string" }
}
},
"personal_info":{
"type":"object",
"properties":{
"title":{ "index":"no", "type":"string" },
"name":{
"type":"multi_field",
"fields":{
"name":{ "type":"string", "analyzer":"name_analyzer", "store":true, "boost":10},
"lower":{ "type":"string", "analyzer":"lower_keyword", "boost":20 },
"untouched":{ "type":"string", "index":"not_analyzed", "store":true }
}
}
}
},
"professions":{
"type":"nested",
"properties":{
"current":{ "type":"boolean" },
"company":{
"type":"multi_field",
"fields":{
"company":{ "type":"string", "analyzer":"name_analyzer", "store":true, "boost":10 },
"lower":{ "type":"string", "analyzer":"lower_keyword", "boost":20 },
"untouched":{ "type":"string", "index":"not_analyzed", "store":true }
}
}
}
}
}
}
},
"settings":{
"number_of_shards":1,
"analysis":{
"tokenizer":{
"name_tokenizer":{ "type":"edgeNGram", "max_gram":100, "min_gram":3, "side":"front" }
},
"analyzer":{
"name_analyzer":{ "tokenizer":"whitespace", "type":"custom", "filter":["lowercase", "multi_words", "name_filter"] },
"lower_keyword":{ "tokenizer":"keyword", "type":"custom", "filter":["lowercase"] },
"multi_words":{ "tokenizer":"standard", "type":"custom", "filter":["standard", "lowercase", "stop", "multi_words"] }
},
"filter":{
"multi_words":{ "type":"shingle", "max_shingle_size":10 },
"name_filter":{ "type":"edgeNGram", "max_gram":100, "min_gram":3, "side":"front" },
"name_filter_reverse":{ "type":"edgeNGram", "max_gram":100, "min_gram":3, "side":"back" }
}
}
}
}
'
curl -X POST "http://localhost:9200/test_users/user/4eb8f6a475f38e4bc1001726" -d '
{
"_id":"4eb8f6a475f38e4bc1001726",
"_type":"User",
"alma_info":{
"_id":"4eb8f6a475f38e4bc1001725",
"branch":"IT",
"course":"M.Tech.",
"department":"Mechanical",
"designation":"Professor",
"graduation_year":2005,
"joining_year":2003,
"rollno":"LD7793-2651",
"discipline":"M.Tech. - IT"
},
"college_id":"4eb8f0f575f38e461700000c",
"created_at":"2011-11-08T09:30:12Z",
"email":"kameron@creminupton.info",
"personal_info":{
"_id":"4eb8f6a475f38e4bc1001724",
"dob":"1984-07-19T00:00:00+05:30",
"fname":"Martine",
"gender":null,
"lname":"Jewess",
"married":false,
"title":null,
"name":"Martine Jewess",
"hometown_string":null,
"current_city_string":null
},
"professions":[
{
"_id":"4ebc205775f38e0c9e000053",
"company":"Adobe Systems",
"company_site":"",
"current":true,
"department":"None",
"description":"",
"designation":"Developer",
"from":"2011-03-31T18:30:00Z",
"location_id":"7279746",
"to":null
}
],
"profile_completeness":20.454545454545457,
"updated_at":"2011-11-10T19:04:04Z",
"user_type":"alumni"
}
'
curl -X POST "http://localhost:9200/test_users/user/4eb8f6a475f38e4bc100172a" -d '
{
"_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",
"created_at":"2011-11-08T09:30:12Z",
"email":"casey.bins@lesch.com",
"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,
"updated_at":"2011-11-10T19:02:34Z",
"user_type":"student"
}
'
curl -X POST "http://localhost:9200/test_users/user/4eb8f0f675f38e4617000025" -d '
{
"_id":"4eb8f0f675f38e4617000025",
"email":"demo.alumni@almaconnect.com",
"user_type":"alumni",
"college_id":"4eb8f0f575f38e461700000c",
"raw_user_id":"4eb8f0f675f38e4617000022",
"_type":"User",
"invitation_token":"kAGTTO55uxxKyDV114Iu",
"updated_at":"2011-11-08T09:05:58Z",
"profile_completeness":14.772727272727273,
"created_at":"2011-11-08T09:05:58Z",
"alma_info":{
"_id":"4eb8f0f675f38e4617000027",
"branch":"ICT",
"course":"B.Tech.",
"graduation_year":2009,
"joining_year":2005,
"rollno":"200511070",
"discipline":"B.Tech. - ICT"
},
"personal_info":{
"_id":"4eb8f0f675f38e4617000026",
"dob":"1987-07-06T00:00:00+05:30",
"fname":"Alumni",
"lname":"Demo",
"name":"Alumni Demo",
"hometown_string":null,
"current_city_string":null
}
}
'
curl -X GET "http://localhost:9200/test_users/user/_search?pretty=true" -d '
{
"sort":[
{ "profile_completeness":"desc" },
{ "created_at":"asc" }
],
"facets":{
"companies":{
"terms":{ "field":"professions.company.untouched", "size":10, "all_terms":false },
"nested":"professions",
"facet_filter":null
}
},
"size":0,
"from":0
}
'
curl -X GET "http://localhost:9200/test_users/user/_search?pretty=true" -d '
{
"query":{ "match_all":{ }},
"facets":{
"companies":{
"terms":{ "field":"professions.company.untouched", "size":10, "all_terms":false },
"nested":"professions",
"facet_filter":null
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment