database - 是否可以实时自动从 elasticsearch 中删除早于例如 10 天的数据?

标签 database elasticsearch lucene nosql search-engine

curl -XGET '127.0.0.1:9200/messages/message/_search?pretty' 返回如下所示的数据。我想知道是否有可能最好实时地从 elasticsearch 中自动删除早于例如 10 天的数据?我添加了我的示例数据,因为有一个字段 date 可以在这种情况下使用。或者可能有其他更推荐的方法?

{
  "took" : 22,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 2,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "messages",
        "_type" : "message",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "message" : "example message1"
        }
      },
      {
        "_index" : "messages",
        "_type" : "message",
        "_id" : "ZODslt0LZ1T6GMrC",
        "_score" : 1.0,
        "_source" : {
          "date" : "2018-05-25T10:06:06Z",
          "message" : "example message1"
        }
      }
    ]
  }
}

最佳答案

弹性 Curator正是您要寻找的。您应该为每一天的索引创建一个单独的文件。

例如,如果您的索引具有这样的模式:YOUR_INDEX_NAME-%{+YYYY.MM.dd} 那么您应该应用以下配置:

actions:
  1:
    action: delete_indices
    options:
      ignore_empty_list: True
      timeout_override:
      continue_if_exception: False
      disable_action: False
    filters:
    - filtertype: pattern
      kind: prefix
      value: YOUR_INDEX_NAME-
      exclude:
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'  <--- date pattern in your index name
      unit: days
      unit_count: 10          <--- after how many days delete the index

关于database - 是否可以实时自动从 elasticsearch 中删除早于例如 10 天的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50525359/

相关文章:

lucene - 在 Lucene/Lucene.net 搜索中,如何计算每个文档的点击次数?

mysql - 追随者/关注关系

php - "PHP combined with MySQL are cross-platform (you can develop in Windows and serve on a Unix platform)"到底是什么意思?

Android:如何创建我自己的游标类?

node.js - 如何在elasticsearch中设置计数器字段

elasticsearch - Elasticsearch到通配符搜索电子邮件地址

database - yii2 使用 ActiveRecord 批量插入

django - django-elasticsearch-dsl-drf建议网址给出404错误

lucene 短语查询不起作用

java - 如何自动从html页面创建模板?