Created
September 9, 2013 15:57
-
-
Save anonymous/6497664 to your computer and use it in GitHub Desktop.
Elasticsearch Statistical Facets work with either script or filter, but not both example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}, | |
"records": { | |
"type": "object", "index": "not_analyzed", "include_in_parent":"true", | |
"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", | |
"records": [ | |
{"name": "weight1", "count": 16}, | |
{"name": "weight2", "count": 54} | |
] | |
}' && echo | |
curl -XPUT 'http://localhost:9200/tester/test/1' -d '{ | |
"name": "searchterm banana second", | |
"records": [ | |
{"name": "weight3", "count": 6}, | |
{"name": "weight6", "count": 5} | |
] | |
}' && echo | |
curl -XPOST 'http://localhost:9200/tester/_refresh' && echo | |
#JSON Queries | |
#valid results | |
{"query": | |
{"query": | |
{"filtered": | |
{"query": | |
{"match_all": | |
{} | |
} | |
} | |
} | |
}, | |
"facets":{ | |
"counts":{ | |
"statistical":{ | |
"field":"records.count" | |
}, | |
"facet_filter" : { | |
"term" : { "name" : "kimchy"} | |
} | |
} | |
} | |
} | |
#valid results | |
{"query": | |
{"query": | |
{"filtered": | |
{"query": | |
{"match_all": | |
{} | |
} | |
} | |
} | |
}, | |
"facets":{ | |
"counts":{ | |
"statistical":{ | |
"field":{ | |
"_script":{ | |
"script":"sum(doc['records.count'].values)", | |
"lang":"python" | |
} | |
} | |
} | |
} | |
} | |
} | |
#non-real infinite results | |
{"query": | |
{"query": | |
{"filtered": | |
{"query": | |
{"match_all": | |
{} | |
} | |
} | |
} | |
}, | |
"facets":{ | |
"counts":{ | |
"statistical":{ | |
"field":{ | |
"_script":{ | |
"script":"sum(doc['records.count'].values)", | |
"lang":"python" | |
} | |
} | |
}, | |
"facet_filter" : { | |
"term" : { "name" : "kimchy"} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment