Skip to content

Instantly share code, notes, and snippets.

@drewr
Last active December 17, 2015 08:09
Show Gist options
  • Select an option

  • Save drewr/5578431 to your computer and use it in GitHub Desktop.

Select an option

Save drewr/5578431 to your computer and use it in GitHub Desktop.
#!/bin/sh
curl -s -XPUT localhost:9200/_template/test -d '
{
"mappings": {
"_default_": {
"_all": {
"enabled": false
}
},
"t": {
"properties": {
"foo": {
"type": "date"
}
}
}
},
"order": 0,
"settings": {
"mapping.ignore_malformed": true,
"number_of_replicas": 0,
"number_of_shards": 5,
"query.default_field": "_logtext"
},
"template": "test*"
}'; echo
curl -s -XDELETE localhost:9200/test >/dev/null
curl -s -XPOST localhost:9200/test/t/1 -d'
{
"foo":1368556626000
}
'; echo
curl -s -XPOST localhost:9200/test/t/2 -d'
{
"foo":"2013-05-14T00:00:00.Z"
}
'; echo
curl -s localhost:9200/test/_settings; echo
# {
# "test": {
# "settings": {
# "index.mapping.ignore_malformed": "true",
# "index.number_of_replicas": "0",
# "index.number_of_shards": "5",
# "index.query.default_field": "_logtext",
# "index.version.created": "900099"
# }
# }
# }
curl -s localhost:9200/test/_mapping; echo
# {
# "test": {
# "_default_": {
# "_all": {
# "enabled": false
# },
# "properties": {}
# },
# "t": {
# "_all": {
# "enabled": false
# },
# "properties": {
# "foo": {
# "format": "dateOptionalTime",
# "type": "date"
# }
# }
# }
# }
# }
curl -s localhost:9200/test/t/1
# {
# "_id": "1",
# "_index": "test",
# "_source": {
# "foo": 1368556626000
# },
# "_type": "t",
# "_version": 1,
# "exists": true
# }
curl -s localhost:9200/test/t/2
# {
# "_id": "2",
# "_index": "test",
# "_source": {
# "foo": "2013-05-14T00:00:00.Z"
# },
# "_type": "t",
# "_version": 1,
# "exists": true
# }
curl -s -XPOST localhost:9200/test/_refresh >/dev/null
curl -s localhost:9200/test/_search -d'
{
"query": {
"range": {
"foo": {
"gte": "2013-05-01"
}
}
}
}'
## Only one hit:
# {
# "_shards": {
# "failed": 0,
# "successful": 5,
# "total": 5
# },
# "hits": {
# "hits": [
# {
# "_id": "1",
# "_index": "test",
# "_score": 1.0,
# "_source": {
# "foo": 1368556626000
# },
# "_type": "t"
# }
# ],
# "max_score": 1.0,
# "total": 1
# },
# "timed_out": false,
# "took": 42
# }
curl -s -XDELETE localhost:9200/_template/test; echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment