Skip to content

Instantly share code, notes, and snippets.

@nono
Created October 9, 2014 10:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nono/d431f9b413cef6bf81c9 to your computer and use it in GitHub Desktop.
Save nono/d431f9b413cef6bf81c9 to your computer and use it in GitHub Desktop.
Use null_value for a date field in Elasticsearch mapping
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [ {
"_index" : "test",
"_type" : "doc",
"_id" : "2",
"_score" : 1.0,
"_source":{
"cards": "2",
"last_updated": "2013-02-02 01:02:03"
}
}, {
"_index" : "test",
"_type" : "doc",
"_id" : "3",
"_score" : 1.0,
"_source":{
"cards": "3",
"last_updated": null
}
} ]
}
}
#!/bin/bash
curl -XDLETE localhost:9200/test
echo
curl -XPUT localhost:9200/test -d '{
"settings": {
"index.number_of_shards": 1,
"index.number_of_replicas": 0
},
"mappings": {
"doc": {
"_timestamp": {
"enabled": "true"
},
"properties": {
"cards": {
"type": "integer"
},
"last_updated": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss",
"null_value": "now"
}
}
}
}
}
'
curl -XPOST localhost:9200/test/doc/1 -d '{
"cards": "1",
"last_updated": "2012-01-01 12:13:14"
}
'
curl -XPOST localhost:9200/test/doc/2 -d '{
"cards": "2",
"last_updated": "2013-02-02 01:02:03"
}
'
curl -XPOST localhost:9200/test/doc/3 -d '{
"cards": "3",
"last_updated": null
}
'
curl -X POST 'http://localhost:9200/test/_refresh'
echo
curl -X GET 'http://localhost:9200/test/doc/_search?pretty' -d '{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"range": {
"last_updated": {
"gte": "2013-01-01 00:00:00"
}
}
}
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment