考虑在我记录的事件中搜索,我遇到了砖墙。我正在使用 elasticsearch 解决方案、filebeat 将消息从日志加载到 elasticsearch 和 Kibana 前端。
我目前将消息记录到一个字段 message
和异常堆栈跟踪(如果存在)到 error.message
.所以记录的事件的片段可能如下所示:
{
"message": "Thrown exception: CustomException (Exception for testing purposes)"
"error" : {
"message" : "com.press.controller.CustomException: Exception for testing purposes\n at
com.press.controller....<you get the idea at this point>"
}
}
当然还有其他字段,如时间戳,但这些并不重要。重要的是:
当我搜索
message : customException
,我可以找到我记录的事件。当我搜索 error.message : customException
,我没有得到事件。我需要能够全文搜索所有字段。有没有办法告诉elasticsearch在字段中启用全文搜索?
为什么“消息”字段默认启用它?我的同事都没有意识到部署后在控制台中的字段上运行了任何索引命令,我们的权限不允许我或其他团队成员在任何字段上运行索引或分析命令。所以它必须在配置中的某个地方。
到目前为止,我无法找到解决方案。请把我推向正确的方向。
编辑:
字段配置如下:
我们使用修改后的 ECS,并且两个消息都声明为
level: core
type: text
在文件中
fields.yml
.在 filebeat 中,配置片段是这样的:
filebeat.inputs:
- type: log
enabled: true
paths: .....
...
...
processors:
- rename:
fields:
- from: "msg"
to: "message"
- from: "filepath"
to: "log.file.name"
- from: "ex"
to: "error.message"
ignore_missing: true
fail_on_error: true
logging.level: debug
logging.to_files: true
出于安全要求,我不能透露完整文件。另外,我需要手工编写所有片段,所以拼写错误可能是我的错。
谢谢
最佳答案
问题在于与您的字段关联的分析器,默认情况下,对于 ES 中的文本字段,使用标准分析器,如果文本包含 .
,则不会创建单独的标记。例如:foo.bar
将导致只有 1 个 token 为 foo.bar
而如果你同时想要 foo
和 bar
应该匹配 foo.bar
那么你需要生成 2 个 token 作为 foo
和 bar
.
您需要的是一个自定义分析器,它可以创建与您的 error.message
相同的 token 。文本包含 .
我在我的例子中解释过:
PUT /my_index
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "standard",
"char_filter": ["replace_dots"]
}
},
"char_filter": {
"replace_dots": {
"type": "mapping",
"mappings": [
". => \\u0020"
]
}
}
}
}
}
POST /my_index/_analyze
{
"analyzer": "my_analyzer",
"text": "foo.bar"
}
上面的例子创建了 2 个 token 作为
foo
和 bar
当您使用这些 API 创建和测试它时,同样应该发生在您身上。如果您遇到任何问题,请告诉我。
关于Elasticsearch - 启用字段的全文搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58911548/