sakutarou’s blog

とりあえずWeb系技術をゆるく書いていく

Elasticsearchのdate型でInvalid format言われた場合の対処方法

こんな感じのマッピングを作成して、 accesstime2018/08/16 19:00:00 のような日時を入れたら Invalid format 言われた場合 format を指定したら解決
elasticsearch的にこの方法がいいのかは検討する必要あるけど、とりあえず今はこれでOK

修正前

curl -XPUT "http://172.17.0.2:9200/my_index" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "my_type": {
      "properties" : {
        "host": {"type":"keyword"},
        "method": {"type":"keyword"},
        "accesstime": {"type": "date"}
      }
    }
  }
}'

修正後

curl -XPUT "http://172.17.0.2:9200/my_index" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "my_type": {
      "properties" : {
        "host": {"type":"keyword"},
        "method": {"type":"keyword"},
        "accesstime": {
          "type": "date",
          "format": "yyyy/MM/dd HH:mm:ss"
        }
      }
    }
  }
}'