2012-12-11 90 views
3

我想配置我的elasticsearch 0.19.11刪除索引每60秒。我elasticsearch配置有以下3行:Elasticsearch:自動索引刪除/到期

node.name: "Saurajeet" 
index.ttl.disable_purge: false 
index.ttl.interval: 60s 
indices.ttl.interval: 60s 

而且它不工作 我有索引2個默認文檔。並會期待它去後60

$ curl -XGET http://localhost:9200/twitter/_settings?pretty=true 
{ 
    "twitter" : { 
    "settings" : { 
     "index.version.created" : "191199", 
     "index.number_of_replicas" : "1", 
     "index.number_of_shards" : "5" 
    } 
} 

另外,如果我嘗試做到這一點亙古不變的有

$ curl -XPUT http://localhost:9200/twitter/_settings -d ' 
> { "twitter": { 
>  "settings" : { 
>  "index.ttl.interval": "60s" 
> } 
> } 
> } 
> ' 
{"ok":true}~/bin/elasticsearc 
$ curl -XGET http://localhost:9200/twitter/_settings?pretty=true 
{ 
    "twitter" : { 
    "settings" : { 
     "index.version.created" : "191199", 
     "index.number_of_replicas" : "1", 
     "index.number_of_shards" : "5" 
    } 
    } 
} 

我有索引2個文件和其仍呈現1小時

之後的任何效果如下
$ curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d ' 
{ 
    "user": "kimchy", 
    "postDate": "2009-11-15T13:12:00", 
    "message": "Trying out Elastic Search, so far so good?" 
}' 
$ curl -XPUT 'http://localhost:9200/twitter/tweet/2' -d ' 
{ 
    "user": "kimchy", 
    "postDate": "2009-11-15T13:12:00", 
    "message": "Trying out Elastic Search, so far so good?" 
}' 

我做了什麼錯

P.S.我想用logstash部署這個配置。因此可以建議任何其他選擇。 因爲縮放的原因,我不希望這個autopurge是一個腳本。

回答

1

終於想通了自己。將elasticsearch版本升級到1.2.0。您可以從Mapping API中輸入TTL。 - >Put Mapping - >TTL

上的索引啓用上型水平TTL

$ curl -XPOST http://localhost:9200/abc/a/_mapping -d ' 
{ 
    "a": { 
     "_ttl": { 
     "enabled": true, 
     "default": "10000ms" 
     } 
    } 
}' 

$ curl -XPOST http://localhost:9200/abc/a/a1 -d '{"test": "true"}' 
$ $ curl -XGET http://localhost:9200/abc/a/a1?pretty 
{ 
    "_index" : "abc", 
    "_type" : "a", 
    "_id" : "a1", 
    "_version" : 1, 
    "found" : true, 
    "_source":{"test": "true"} 
} 
$ # After 10s 
$ curl -XGET http://localhost:9200/abc/a/a1?pretty 
{ 
    "_index" : "abc", 
    "_type" : "a", 
    "_id" : "a1", 
    "found" : false 
} 

注:

  • 映射適用於創建映射之後創建的文檔。
  • 此外,還爲類型a創建了映射。因此,如果您發佈的類型爲b並且 預計會在TTL上過期,那麼這種情況不會發生。

如果你需要到期索引,你也可以在create index期間創建索引級映射,以便從您的應用程序邏輯預先創建索引。

相關問題