Created
December 3, 2012 13:55
-
-
Save AnSavvides/4195194 to your computer and use it in GitHub Desktop.
action_histograms fix?
This file contains 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
# Create an index: | |
# | |
curl -XDELETE 'http://127.0.0.1:9200/articles' | |
curl -XPUT 'http://127.0.0.1:9200/articles' | |
# Insert the action mapping, as a child of articles: | |
# | |
curl -XPUT 'http://127.0.0.1:9200/articles/article/_mapping' -d ' | |
{ | |
"article": { | |
"properties": { | |
"title": { | |
"store": true, | |
"type": "string" | |
}, | |
"actions": { | |
"type": "nested", | |
"properties": { | |
"action": { | |
"store": true, | |
"type": "string" | |
}, | |
"date": { | |
"store": true, | |
"format": "dateOptionalTime", | |
"type": "date" | |
} | |
} | |
} | |
} | |
} | |
} | |
' | |
# Insert some articles: | |
# | |
for ((i=1; i<14; i++)) | |
do | |
curl -XPUT 'http://127.0.0.1:9200/articles/article/'$i -d ' | |
{ | |
"title": "Article '$i'", | |
"actions": [ | |
{"date": "2010-11-18", "action": "updated"} | |
] | |
} | |
' | |
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 | |
# on the 18th of November, 2010. Create facets for those actions: | |
# | |
curl -XGET 'http://127.0.0.1:9200/articles/_search?pretty=true' -d ' | |
{ | |
"query": { | |
"bool": { | |
"must": [ | |
{ "query_string": {"query": "title:\"Article 1\""} }, | |
{ | |
"nested": { | |
"path": "actions", | |
"score_mode": "avg", | |
"_scope": "actions", | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"range": { | |
"actions.date": { | |
"from": "2010-11-18", | |
"to": "2010-11-18" | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
} | |
] | |
} | |
}, | |
"facets": { | |
"updated_facet": { | |
"date_histogram": { | |
"interval": "day", | |
"key_field": "actions.date", | |
"value_script": "1" | |
}, | |
"scope": "actions" | |
} | |
}, | |
"from": 0, | |
"size": 0 | |
}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment