繁体   English   中英

如何在Elasticsearch中获取索引的最新更新

[英]How to get the last update of the index in elasticsearch

如何找到elsasticsearch索引的最新更新日期时间? Elasticsearch索引的上次更新时间我尝试遵循该示例,但没有任何反应。

curl -XGET 'http://localhost:9200/_all/_mapping'
{"haystack":{"mappings":{"modelresult":{"_all":{"auto_boost":true},"_boost":{"name":"boost","null_value":1.0},"properties":{"act_name":{"type":"string","boost":1.3,"index_analyzer":"index_ngram","search_analyzer":"search_ngram"},"django_ct":{"type":"string","index":"not_analyzed","include_in_all":false},"django_id":{"type":"string","index":"not_analyzed","include_in_all":false},"hometown":{"type":"string","boost":0.9,"index_analyzer":"index_ngram","search_analyzer":"search_ngram"},"id":{"type":"string"},"text":{"type":"string","analyzer":"ngram_analyzer"}}},"mytype":{"_timestamp":{"enabled":true,"store":true},"properties":{}}}}}

curl -XPOST localhost:9200/your_index/your_type/_search -d '{
  "size": 1,
  "sort": {
    "_timestamp": "desc"
  },
  "fields": [
    "_timestamp"
  ]
}'
{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":99,"max_score":null,"hits":[{"_index":"haystack","_type":"modelresult","_id":"account.user.96","_score":null,"sort":[-9223372036854775808]}]}}

怎么了?

首先,您需要做的就是按照该链接的问题进行操作,并在映射中启用_timestamp字段

{
    "modelresult" : {
        "_timestamp" : { "enabled" : true }
    }
}

然后,您可以查询具有最新时间戳的单个文档的索引,如下所示:

curl -XPOST localhost:9200/haystack/modelresult/_search -d '{
  "size": 1,
  "sort": {
    "_timestamp": "desc"
  },
  "fields": [
    "_timestamp"
  ]
}'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM