node.js - 在带有时间戳的 kibana 中没有结果符合您的搜索条件
问题描述
我在 elasticsearch 6.5.1 中创建了一个索引,成功地将数据加载到该索引。有一个字段 "submitted_date"
是时间戳。下面是这个字段的映射。
"submitted_date": { "type": "date", "format":"yyyy-MM-dd HH:mm:ss.SSS" },
然后我创建了索引模式。我用Time Filter field name
as "submitted_date"
。之后,我尝试检查“发现”选项卡中的数据,但没有显示数据。有消息说No results match your search criteria
。
请注意,我已经以各种可能的方式更改了时间范围选择器,它位于 kibana 仪表板右上角。
数据显示在带有弹性查询的开发工具选项卡中。
ps:我使用nodejs和elasticsearch官方库插入数据,没有使用logstash。
我关注了这篇文章,但它对我没有帮助。
更新:示例文档
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 10480,
"max_score" : 1.0,
"hits" : [
{
"_index" : "test",
"_type" : "tests",
"_id" : "1214334",
"_score" : 1.0,
"_source" : {
"priority" : "4",
"submitted_date" : "2018-01-04T18:32:21.000Z",
"submitted_month" : 0,
"submitted_month_name" : "January",
"submitted_day" : 4,
"submitted_weekday" : "Tuesday",
"submitted_hour" : 18,
"submitted_year_month" : "2018-0",
"submitted_year_month_name" : "2018-January",
"date_key" : "20180104",
"year_month_key" : "201801",
"status" : "Closed"
}
}
]
}
}
检查请求
{
"version": true,
"size": 500,
"sort": [
{
"_score": {
"order": "desc"
}
}
],
"_source": {
"excludes": []
},
"aggs": {
"2": {
"date_histogram": {
"field": "submitted_date",
"interval": "1d",
"time_zone": "Asia/Kolkata",
"min_doc_count": 1
}
}
},
"stored_fields": [
"*"
],
"script_fields": {},
"docvalue_fields": [
{
"field": "close_date",
"format": "date_time"
},
{
"field": "last_modified_date",
"format": "date_time"
},
{
"field": "last_resolved_date",
"format": "date_time"
},
{
"field": "submitted_date",
"format": "date_time"
},
{
"field": "time_to_resolve",
"format": "date_time"
}
],
"query": {
"bool": {
"must": [
{
"match_all": {}
},
{
"range": {
"submitted_date": {
"gte": 1514745000000,
"lte": 1543937620414,
"format": "epoch_millis"
}
}
}
],
"filter": [],
"should": [],
"must_not": []
}
},
"highlight": {
"pre_tags": [
"@kibana-highlighted-field@"
],
"post_tags": [
"@/kibana-highlighted-field@"
],
"fields": {
"*": {}
},
"fragment_size": 2147483647
}
}
索引模式
function _putMapping() {
return client.indices.create({
index: process.env.ELASTICSEARCH_INDEX,
body: {
settings:{
index:{
"number_of_shards": 1,
"number_of_replicas": 5
},
"index.mapping.ignore_malformed" : true
},
mappings:{
tests:{
properties:{
"last_modified_date": { "type": "date" },
"last_resolved_date": { "type": "date" },
"time_to_resolve": { "type": "date" },
"submitted_date": { "type": "date", "format":"yyyy-MM-dd HH:mm:ss.SSS" },
"date_key": { "type": "integer" },
"priority": { "type": "long" },
"submitted_hour": { "type": "long" },
"submitted_month": { "type": "long" },
"submitted_year": { "type": "long" },
"submitted_year": { "type": "keyword" },
"submitted_year_month": { "type": "keyword" },
"submitted_year_month_name": { "type": "keyword" },
}
}
}
}
});
}
解决方案
您的 mYoursubmitted_date
即将到来,2018-01-04T18:32:21.000Z
但您的映射设置为yyyy-MM-dd HH:mm:ss.SSS
.
您需要将其更改为"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
.
推荐阅读
- pandas - Pandas:链接时更改系列索引
- ios - 在范围内找不到类型“GADInterstitial”?
- mysql - 如何创建仅在其中一行包含所需值时才返回结果的 SQL 语句?
- c# - 将字符串转换为 int,然后再转换回字符串
- python - 如何动态替换 pandas.Series 中的值?
- javascript - 如何以角度访问 HTTP 错误响应正文
- c - 索引“unsigned long”变量并打印结果
- java - 为什么每个栈帧都有自己的操作数栈?
- azure - 新创建的 azure 广告组在 azure devops(rest api)中不可用
- html - 在 Rails 视图中,如何在 HTML 代码片段中显示动态代码?