Skip to content

Instantly share code, notes, and snippets.

@AnSavvides
Created December 3, 2012 20:05
Show Gist options
  • Save AnSavvides/4197614 to your computer and use it in GitHub Desktop.
Save AnSavvides/4197614 to your computer and use it in GitHub Desktop.
action_histograms real fix
# Create an index:
#
curl -XDELETE 'http://127.0.0.1:9200/articles'
curl -XPUT 'http://127.0.0.1:9200/articles' -d '
index :
number_of_shards : 1
'
# Insert the action mapping:
#
curl -XPUT 'http://127.0.0.1:9200/articles/article/_mapping' -d '
{
"article": {
"properties": {
"title": {
"store": true,
"type": "string"
}
}
}
}
'
# Insert some articles:
#
for ((i=1; i<15; i++))
do
curl -XPUT 'http://127.0.0.1:9200/articles/article/'$i -d '
{
"title": "Article '$i'",
"actions_updated": ["2010-11-18"],
"actions_published": ["2010-11-19","2010-11-20"]
}
'
done
# Ensure the index is up-to-date:
#
curl -XPOST 'http://127.0.0.1:9200/articles/_refresh'
# Now search for some articles that have actions that took place
# between the 18th and 20th of November, 2010.
# Create facets for those actions:
#
curl -XGET 'http://127.0.0.1:9200/articles/_search?pretty=true' -d '
{
"query": {
"filtered": {
"query": { "query_string": {"query": "title:\"Article 1\""} }
}
},
"facets": {
"updated_facet": {
"date_histogram": {
"interval": "day",
"key_field": "actions_updated"
},
"facet_filter": {
"range": {
"actions_updated": { "from": "2010-11-18", "to": "2010-11-20" }
}
}
},
"published_facet": {
"date_histogram": {
"interval": "day",
"key_field": "actions_published"
},
"facet_filter": {
"range": {
"actions_published": { "from": "2010-11-18", "to": "2010-11-20" }
}
}
}
},
"from": 0,
"size": 0
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment