且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使elasticsearch将时间戳字段添加到所有索引中的每个文档?

更新时间:2023-02-08 19:36:44

您可以通过在创建索引时提供它来做到这一点.

You can do this by providing it when creating your index.

$curl -XPOST localhost:9200/test -d '{
"settings" : {
    "number_of_shards" : 1
},
"mappings" : {
    "_default_":{
        "_timestamp" : {
            "enabled" : true,
            "store" : true
        }
    }
  }
}'

然后会自动为所有人创建一个 _timestamp你放入索引的东西.然后在请求 _timestamp 字段时索引某些内容后,它将被返回.

That will then automatically create a _timestamp for all stuff that you put in the index. Then after indexing something when requesting the _timestamp field it will be returned.