Search code examples
elasticsearchelasticsearch-mapping

Elasticsearch _timestamp


I tried to define the _timestamp property on an index. So first, I create the index

curl -XPUT 'http://elasticsearch:9200/ppe/'

response from the server : {"ok":true,"acknowledged":true}

then I tried to define the mapping with a _timestamp

curl -Xput 'http://elasticsearch:9200/ppe/log/_mapping' -d '{
  "log": {
    "properties": {
      "_ttl": {
        "enabled": true
      },
      "_timestamp": {
        "enabled": true,
        "store": "yes"
      },
      "message": {
        "type": "string",
        "store": "yes"
      },
      "appid": {
        "type": "string",
        "store": "yes"
      },
      "level": {
        "type": "integer",
        "store": "yes"
      },
      "logdate": {
        "type": "date",
        "format": "date_time_no_millis",
        "store": "yes"
      }
    }
  }
}'

and I receive as answer from the server

{
  "error": "MapperParsingException[No type specified for property [_timestamp]]",
  "status": 400
}

What's wrong with my mapping?


Solution

  • Special fields such as _ttl and _timestamp have to be defined on the same level as the properties object:

    curl -Xput 'http://elasticsearch:9200/ppe/log/_mapping' -d '{
        "log": {
            "_ttl": {
                "enabled": true
            },
            "_timestamp": {
                "enabled": true,
                "store": "yes"
            },
            "properties": {
                "message": {
                    "type": "string",
                    "store": "yes"
                },
                "appid": {
                    "type": "string",
                    "store": "yes"
                },
                "level": {
                    "type": "integer",
                    "store": "yes"
                },
                "logdate": {
                    "type": "date",
                    "format": "date_time_no_millis",
                    "store": "yes"
                }
            }
        }
    }
    '