在Kibana索引模式中不将日期字段视为时间戳字段

您所在的位置:网站首页 long类型时间戳转 在Kibana索引模式中不将日期字段视为时间戳字段

在Kibana索引模式中不将日期字段视为时间戳字段

2023-03-13 16:23| 来源: 网络整理| 查看: 265

我一直在尝试为文档中的日期值获得正确的Map。现在我已经用它做了大量的尝试。每次,无论我尝试什么选项,我都没有在创建Kibana索引模式时将文档中的日期字段视为时间戳列。以下是我在索引Map中尝试过的各种选项(点击和试用,因为我觉得自己在ELK:blush:上完全是个菜鸟):

试验1:

{ "mappings" : { "properties" : { "Created" : { "type" : "date", "fields" : { "keyword" : { "type" : "keyword" } }, "format": "strict_date_optional_time||epoch_millis" }, "Due date" : { "type" : "date", "fields" : { "keyword" : { "type" : "keyword" } }, "format": "strict_date_optional_time||epoch_millis" }, "Updated" : { "type" : "date", "fields" : { "keyword" : { "type" : "keyword" } }, "format": "strict_date_optional_time||epoch_millis" } } } }

试验2

{ "mappings" : { "properties" : { "Created" : { "type" : "date", "fields" : { "keyword" : { "type" : "keyword" } } }, "Due date" : { "type" : "date", "fields" : { "keyword" : { "type" : "keyword" } } }, "Updated" : { "type" : "date", "fields" : { "keyword" : { "type" : "keyword" } } } } } }

第三次审判

{ "mappings" : { "properties" : { "Created" : { "type" : "date", "fields" : { "keyword" : { "type" : "date" } } }, "Due date" : { "type" : "date", "fields" : { "keyword" : { "type" : "date" } } }, "Updated" : { "type" : "date", "fields" : { "keyword" : { "type" : "date" } } } } } }

然后将上面的每个试验与下面的试验进行比较:

"_default_": { "_timestamp": { "enabled": true, "store": true, "_field_names": "_timestamp" } },

然后每个

"fields" : { "keyword" : { "type" : "date" }

用格式再次明确地指定上面的每一个组合.这就是我的示例文档看起来的样子(不同的试验)

试验文件1

{ "Created": "15/11/21 13:21", "Updated": "30/12/21 14:30", "Due date": null }

尝试文档2

{ "Created": 1636982460000, "Updated": 1640874600000, "Due date": null }

而且在Kibana中创建索引模式时,上述组合似乎都没有将所需字段作为时间戳字段(Elasticsearch & Kibana 7.15)另外,当发送带有纪元时间的文档时(如 * 试验文档2*),尽管为索引显式定义了Map,但当我从Kibana-〉Index Management查看Map时,它总是显示为long,如下所示:thinking_face:

而在 * 试验文档1* 的情况下,尽管再次将Map明确定义为日期类型(指定或未指定格式),但始终显示为text,如下所示

我确信这里有很多东西需要学习。有人能给我正确的方向吗?以免我最终写一个自动生成各种组合的程序(当然,这将是无脑的&肯定不会带来任何好处:笑一笑:)下面是我如何将数据推送到索引中:

from elasticsearch import Elasticsearch #with open('asb-23-01-2022-18-36-46.json') as f: # with epoch with open('asb-24-01-2022-19-57-44.json') as f: # with date x= json.load(f) es = Elasticsearch([{'host': 'localhost', 'port': '9200'}], http_auth=('elastic', 'password')) mapping = ''' { "properties" : { "Created" : { "type" : "keyword", "fields" : { "keyword" : { "type" : "date", "format":"dd/MMM/yy h:m a" } } }, "Due date" : { "type" : "keyword", "fields" : { "keyword" : { "type" : "date", "format":"dd/MMM/yy h:m a" } } } "Module" : { "type" : "text", "fields" : { "keyword" : { "type" : "keyword", "ignore_above" : 256 } } } } } ''' es.indices.exists(index="'index-name'") or es.indices.create(index='index-name', ignore=400, body=mapping) for item in x: print(x.index(item)) es.index(index='index-name', body=item, ignore=400)

我直接在elasticsearch数据节点上运行上面的代码来推送数据。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3