Skip to content

Instantly share code, notes, and snippets.

@MarneusCalgarXP
Last active December 20, 2015 23:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarneusCalgarXP/473d6d72c5ae7dc04a11 to your computer and use it in GitHub Desktop.
Save MarneusCalgarXP/473d6d72c5ae7dc04a11 to your computer and use it in GitHub Desktop.
Elastic 0.90.2 : facet & nested object
#!/bin/sh
curl -XDELETE http://localhost:9200/records
curl -XPOST http://localhost:9200/records
curl -XPUT http://localhost:9200/records/record/_mapping -d "`cat mapping.json`"
curl -XPUT http://localhost:9200/records/record/1 -d "`cat record-1.json`"
curl -XPUT http://localhost:9200/records/record/2 -d "`cat record-2.json`"
{
"record": {
"properties": {
"id": {"type" : "long"},
"reference" : {"type" : "string", "index": "not_analyzed"},
"situations": {
"type": "nested",
"properties": {
"beginDate": {"type" : "date"},
"endDate": {"type" : "date"},
"type": { "type" : "string", "index": "not_analyzed"}
}
}
}
}
}
{
"id": 1,
"reference": "RECORD-1",
"situations": [
{
"beginDate": 1136847600000,
"endDate": 32472140400000,
"type": "FOO"
}
],
"score": null
}
{
"id": 2,
"reference": "RECORD-2",
"situations": [
{
"beginDate": 1136847600000,
"endDate": 3247214040000,
"type": "BAR"
},
{
"beginDate": 1131564600000,
"endDate": 2654240400000,
"type": "BAZ"
}
],
"score": null
}
{
"query": {
"match_all": {}
},
"facets": {
"facet_situations": {
"global": true,
"nested": "situations",
"terms": {
"field": "situations.type"
},
"facet_filter": {
"term": {
"record.reference": "RECORD-2"
}
}
}
}
}
#!/bin/sh
curl -XPOST http://localhost:9200/records/record/_search?pretty=true -d "`cat request.json`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment