首页 > 解决方案 > Elastic Search 的每日新索引

问题描述

我在 Elastic 有一个索引 time_series。

PUT time_series
{
  "settings": {
    "number_of_shards": 3
  },
  "mappings": {
    "timeseries": {
      "properties": {
                "timestamp" : { 
                  "type" : "date",
                  "format": "MM/dd/yyyy HH:mm:ss"
                  },
                "value" : { "type" : "double" },
                "recordid" : { "type" : "integer" }
      }
    }
  }
}

从 C# 中,我向索引提供数据。我想要一个每天的新索引,比如

到目前为止,我知道我需要设置一个模板。我试过这个,但我得到一个状态= 400。

PUT _template/template_1
{
  "index_patterns": ["time_series*"],
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "timeseries": {
      "enabled": false
    },
    "properties": {
      "host_name": {
        "type": "keyword"
      },
      "created_at": {
        "type": "date",
        "format": "_yyyyMMDD"
      }
    }
  }
}

如何获取每天的新索引?

我需要用当前日期调整 C# 代码中的索引还是自动进入每日索引?

标签: c#elasticsearchasp.net-core-webapi

解决方案


我遇到了几乎同样的问题。我所做的是创建一个控制台项目(因为我还有其他操作要做),每次创建新索引 = 00:01:00。(控制台项目每 5 分钟触发一次)。请参阅此链接,可能会对您有所帮助https://discuss.elastic.co/t/elasticsearch-for-logging-how-to-configure-automatic-creation-of-the-new-index-every-day/19467/3


推荐阅读