如何在elasticsearch中获取索引的最后一次更新

时间:2015-09-15 11:12:51

标签: search indexing full-text-search elasticsearch

如何查找elsasticsearch索引上次更新的日期时间? http://book.cakephp.org/3.0/en/core-libraries/email.html#configuring-transports我试图效仿,但没有发生任何事情。

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]}]}}

有什么问题?

1 个答案:

答案 0 :(得分:0)

首先,您需要做的就是在该链接问题中继续进行,并在映射中启用_timestamp field

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

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

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