且构网

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

弹性搜索索引上次更新时间

更新时间:2023-02-08 19:14:31

您可以从 _timestamp

为了更容易返回时间戳,您可以设置弹性搜索来存储:

To make it easier to return the timestamp you can set up Elasticsearch to store it:

curl -XPUT "http://localhost:9200/myindex/mytype/_mapping" -d'
{
  "mytype": {
      "_timestamp": {
          "enabled": "true",
          "store": "yes"
      }
  }
}'

如果我插入一个文档然后查询它,我得到时间戳:

If I insert a document and then query on it I get the timestamp:

 curl -XGET 'http://localhost:9200/myindex/mytype/_search?pretty' -d '{
>  fields : ["_timestamp"],
>    "query": {
>     "query_string": { "query":"*"}
>    }
> }'
{
   "took" : 7,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
     "total" : 1,
     "max_score" : 1.0,
     "hits" : [ {
       "_index" : "myindex",
       "_type" : "mytype",
       "_id" : "1",
       "_score" : 1.0,
       "fields" : {
        "_timestamp" : 1417599223918
      }
    } ]
  }
}

更新现有文档:

curl -XPOST "http://localhost:9200/myindex/mytype/1/_update" -d'
{
  "doc" : {
      "field1": "data",
      "field2": "more data"
  },
  "doc_as_upsert" : true
}'

重新运行上一个查询会显示更新的时间戳记:

Re-running the previous query shows me an updated timestamp:

  "fields" : {
    "_timestamp" : 1417599620167
  }