Elasticsearch index last update time

前端 未结 2 1831
终归单人心
终归单人心 2020-12-15 21:59

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 docume

相关标签:
2条回答
  • 2020-12-15 22:36

    I don't know if there are people who are looking for an equivalent, but here is a workaround using shards stats for > Elasticsearch 5 users: curl XGET http://localhost:9200/_stats?level=shards

    As you'll see, you have some informations per indices, commits and/or flushs that you might use to see if the indice changed (or not).

    I hope it will help someone.

    0 讨论(0)
  • 2020-12-15 22:52

    You can get the modification time from the _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
          }
        } ]
      }
    }
    

    updating the existing document:

    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
      }
    
    0 讨论(0)
提交回复
热议问题