弹性搜索索引上次更新时间 [英] Elasticsearch index last update time

查看:107
本文介绍了弹性搜索索引上次更新时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从ElasticSearch检索特定索引何时上次更新?
我的目标是能够知道什么时候是在索引中插入/更新/删除任何文档的最后一次。如果这不可能,我可以在我的索引修改请求中添加一些可以在以后提供此信息的内容吗?

Is there a way to retrieve from ElasticSearch information on when a specific index was last updated? My goal is to be able to tell when it was the last time that any documents were inserted/updated/deleted in the index. If this is not possible, is there something I can add in my index modification requests that will provide this information later on?

推荐答案

您可以从 _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
  }

这篇关于弹性搜索索引上次更新时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆