Skip to content

Instantly share code, notes, and snippets.

Created September 5, 2013 22:50
Show Gist options
  • Save anonymous/6457316 to your computer and use it in GitHub Desktop.
Save anonymous/6457316 to your computer and use it in GitHub Desktop.
Elasticsearch Multi-Layered Nested Object: Accessing multiple Nested Layers in a Facet Does not work
curl -XDELETE 'http://localhost:9200/tester
curl -XPUT 'http://localhost:9200/tester' -d '{}'
curl -XPUT 'http://localhost:9200/tester/test/_mapping' -d '{
"authors": {
"properties": {
"name": {"type": "string"},
"keywords": {
"type": "nested",
"properties": {
"words": {"type": "string", "index" : "not_analyzed"},
"records": {
"type": "nested", "index": "not_analyzed",
"properties": {
"name": {"type": "string", "index": "not_analyzed"},
"count": {"type": "integer", "index": "not_analyzed"}
}
}
}
}
}
}
}' && echo
curl -XPUT 'http://localhost:9200/tester/test/1' -d '{
"name": "searchterm banana",
"keywords": [
{
"words": "The Grapes of Wrath",
"records": [
{"name": "weight1", "count": 16},
{"name": "weight2", "count": 54}
]
}
]
}' && echo
curl -XPUT 'http://localhost:9200/tester/test/1' -d '{
"name": "searchterm banana second",
"keywords": [
{
"words": "The Grapes of Wrath text is fun",
"records": [
{"name": "weight3", "count": 6},
{"name": "weight6", "count": 5}
]
}
]
}' && echo
curl -XPOST 'http://localhost:9200/tester/_refresh' && echo
#Search Will get facet results, but the total will always be null
curl -s 'http://localhost:9200/tester/test/_search?pretty=true '{"query":{
"nested":
{"query":
{"filtered":
{"query":
{"match_all":
{}
}
}
},
"path":"keywords"
}
},
"facets":{
"install_stat":{
"nested":"keywords",
"terms_stats":
{"key_field":"keywords.words",
"_script":
{"value_script":"sum(doc['keywords.records.count'].values)",
"lang":"python",
"order":"count",
"size":3,
"nested":"keywords.records"
},
}
}
},"size":3
}' && echo
#Search Will not get any facet results
curl -s 'http://localhost:9200/tester/test/_search?pretty=true '{"query":{
"nested":
{"query":
{"filtered":
{"query":
{"match_all":
{}
}
}
},
"path":"keywords"
}
},
"facets":{
"install_stat":{
"nested":"keywords.records",
"terms_stats":
{"key_field":"keywords.words",
"_script":
{"value_script":"sum(doc['keywords.records.count'].values)",
"lang":"python",
"order":"count",
"size":3,
"nested":"keywords.records"
},
}
}
},"size":3
}' && echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment