Skip to content

Instantly share code, notes, and snippets.

@imotov
Created January 9, 2013 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save imotov/4496959 to your computer and use it in GitHub Desktop.
Save imotov/4496959 to your computer and use it in GitHub Desktop.
curl -XDELETE localhost:9200/date-test
echo
curl -XPUT localhost:9200/date-test -d '{
"settings": {
"index.number_of_shards": 1,
"index.number_of_replicas": 0
},
"mappings": {
"doc": {
"properties": {
"date": {"type":"date", "format" : "YYYY-MM-dd"}
}
}
}
}
'
echo
curl -XPUT localhost:9200/date-test/doc/1 -d '{
"date": "1999-04-23"
}'
echo
curl -XPUT localhost:9200/date-test/doc/2 -d '{
"date": "2000-05-26"
}'
echo
curl -XPOST localhost:9200/date-test/_refresh
echo
echo "Find all records in 1999"
curl "localhost:9200/date-test/doc/_search?pretty=true" -d '{
"query": {
"range": {
"date": {
"include_lower" : true,
"include_upper": false,
"from": "1999-01-01",
"to": "2000-01-01"
}
}
}
}'
echo
echo "Find all records in May of 2000"
curl "localhost:9200/date-test/doc/_search?pretty=true" -d '{
"query": {
"range": {
"date": {
"include_lower" : true,
"include_upper": false,
"from": "2000-05-01",
"to": "2000-06-01"
}
}
}
}'
echo
echo "Find all records in 1999 using lucene query syntax"
curl 'localhost:9200/date-test/_search?pretty=true&q=date:%5B1999-01-01+TO+1999-12-31%5D'
echo
echo "Find all records in May of 2000"
curl "localhost:9200/date-test/_search?pretty=true&q=date:%5B2000-05-01+TO+2000-05-31%5D"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment