gpt4 book ai didi

elasticsearch - 通过API将文档添加到elasticsearch,然后通过kibana发现它们。怎么样?

转载 作者:行者123 更新时间:2023-12-03 01:30:49 27 4
gpt4 key购买 nike

我通常通过logstash插件将数据(日志)插入elasticsearch。然后我
可以从kibana搜索它们。

但是,如果我尝试以编程方式在Elasticsearch中插入数据(为了
跳过filebeat和logstash),则无法在kibana中找到数据。

这是我测试的内容:

from elasticsearch import Elasticsearch
es = Elasticsearch(["XXX"], ...)
doc = {
"@version": 1,
"@timestamp": datetime.now(),
"timestamp": datetime.now(), # Just in case this is needed too
"message": "test message"
}
res = es.index(
index="foobar-2019.05.13", doc_type='whatever', id=3, body=doc,
refresh=True
)
# Doc is indexed by above code, as proved by
# es.search(
# index="foobar-*", body={"query": {"match_all": {}}}
#)

我在“索引模式->创建”中向kibana添加了索引模式“foobar- *”
索引模式”。然后,我可以使用“发现”页面在该页面中搜索文档
指数。但是,kibana找不到任何文件,即使这些文件存在于
elasticsearch。

我缺少什么?是否应该为索引配置任何映射?

(注意:使用6.x版本)

UPDATE:已建立文档索引和索引映射的示例

# Example of doc indexed
{'_index': 'foobar-2019.05.13', '_type': 'doc', '_id': '41', '_score': 1.0,
'_source': {'author': 'foobar', 'message': 'karsa big and crazy. icarium crazy. mappo big.',
'timestamp': '2019-05-13T15:52:19.857898',
'@version': 1, '@timestamp': '2019-05-13T15:52:19.857900'}}

# mapping of foobar-2019.05.13'
{
"mapping": {
"doc": {
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "long"
},
"author": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"message": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"timestamp": {
"type": "date"
}
}
}
}
}

最佳答案

我发现了问题...主机之间的时区差异为2小时
python代码正在运行,elasticsearch / kibana主机。

因此,由于我使用的是datetime.now(),因此要插入带有时间戳“ future 几小时”的文档,并且正在“过去的任何地方”搜索它们。

如果我将来会寻找它们(或者,如果我等待2个小时而不进行更新)
他们),他们被发现。

我这边令人尴尬的错误。

解决的办法是使用datetime.now(timezone.utc)

关于elasticsearch - 通过API将文档添加到elasticsearch,然后通过kibana发现它们。怎么样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56113575/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com