Kibana:在文本中搜索字符串

A_E*_*ric 5 search elasticsearch kibana

我在 Kibana 中有一条日志消息,其中包含以下内容:

org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:597)
Run Code Online (Sandbox Code Playgroud)

不返回结果的实际搜索: log_message: "hibernate3"

如果我搜索“hibernate3”,则不会出现此消息。我正在使用 Elasticsearch 模板并为该字段编制索引,但也希望能够进行不区分大小写的全文搜索。这可能吗?

正在使用的模板:

{
"template": "filebeat-*",
"mappings": {
    "mainProgram": {
        "properties": {
            "@timestamp": {
                "type": "date",
                "format": "strict_date_optional_time||epoch_millis"
            },
            "@version": {
                "type": "text"
            },
            "beat": {
                "properties": {
                    "hostname": {
                        "type": "text"
                    },
                    "name": {
                        "type": "text"
                    }
                }
            },
            "class_method": {
                "type": "text",
                "fielddata": "true",
                "index": "true"
            },
            "class_name": {
                "type": "text",
                "fielddata": "true"
            },
            "clientip": {
                "type": "ip",
                "index": "not_analyzed"
            },
            "count": {
                "type": "long"
            },
            "host": {
                "type": "text",
                "index": "not_analyzed"
            },
            "input_type": {
                "type": "text",
                "index": "not_analyzed"
            },
            "log_level": {
                "type": "text",
                "fielddata": "true",
                "index": "true"
            },
            "log_message": {
                "type": "text",
                "index": "true"
            },
            "log_timestamp": {
                "type": "text"
            },
            "log_ts": {
                "type": "long",
                "index": "not_analyzed"
            },
            "message": {
                "type": "text"
            },
            "offset": {
                "type": "long",
                "index": "not_analyzed"
            },
            "query_params": {
                "type": "text",
                "index": "true"
            },
            "sessionid": {
                "type": "text",
                "index": "true"
            },
            "source": {
                "type": "text",
                "index": "not_analyzed"
            },
            "tags": {
                "type": "text"
            },
            "thread": {
                "type": "text",
                "index": "true"
            },
            "type": {
                "type": "text"
            },
            "user_account_combo": {
                "type": "text",
                "index": "true"
            },
            "version": {
                "type": "text"
            }
        }
    },
    "access": {
        "properties": {
            "@timestamp": {
                "type": "date",
                "format": "strict_date_optional_time||epoch_millis"
            },
            "@version": {
                "type": "text"
            },
            "beat": {
                "properties": {
                    "hostname": {
                        "type": "text"
                    },
                    "name": {
                        "type": "text"
                    }
                }
            },
            "clientip": {
                "type": "ip",
                "index": "not_analyzed"
            },
            "count": {
                "type": "long",
                "index": "not_analyzed"
            },
            "host": {
                "type": "text",
                "index": "true"
            },
            "input_type": {
                "type": "text",
                "index": "not_analyzed"
            },
            "log_timestamp": {
                "type": "text"
            },
            "log_ts": {
                "type": "long",
                "index": "not_analyzed"
            },
            "message": {
                "type": "text"
            },
            "offset": {
                "type": "long",
                "index": "not_analyzed"
            },
            "query_params": {
                "type": "text",
                "index": "true"
            },
            "response_time": {
                "type": "long"
            },
            "sessionid": {
                "type": "text",
                "index": "true"
            },
            "source": {
                "type": "text",
                "index": "not_analyzed"
            },
            "statuscode": {
                "type": "long"
            },
            "tags": {
                "type": "text"
            },
            "thread": {
                "type": "text",
                "index": "true"
            },
            "type": {
                "type": "text",
                "index": "true"
            },
            "uripath": {
                "type": "text",
                "index": "true"
            },
            "user_account_combo": {
                "type": "text",
                "index": "true"
            },
            "verb": {
                "type": "text",
                "index": "true"
            }
        }
    }
}
}
Run Code Online (Sandbox Code Playgroud)

Kul*_*gar 14

根据您的场景,您正在寻找的是一种分析类型string,它首先分析字符串,然后对其进行索引。文档的引用。

换句话说,将此字段作为全文索引。

因此,请确保您正确映射了必要的字段,以便您能够对文档进行全文搜索。

假设,Kibana如果日志行位于 字段 下message,您可以简单地通过以下方式搜索该单词:

message:"hibernate3"
Run Code Online (Sandbox Code Playgroud)

您可能还想参考此内容Term Based,以确定和之间的差异Full-Text

编辑

字段的映射log_message如下:

"log_message": {
       "type": "string", <- to make it analyzed
       "index": "true"
}
Run Code Online (Sandbox Code Playgroud)

还可以尝试进行通配符搜索,如下所示:

{"wildcard":{"log_message":"*.hibernate3.*"}}
Run Code Online (Sandbox Code Playgroud)

  • 我应该指出,如果您的搜索查询包含空格,那么您就不走运了。`log_message:"*thequickbrown*"` 和 `log_message:*thequickbrown*` 都没有按预期工作。为什么 KQL 这么不直观? (2认同)
  • @JonathanNeufeld 只需用双引号将搜索括起来,例如```消息:“敏捷的棕色狐狸”```。你不需要星号。 (2认同)

oto*_*let 11

在 Kibana 6.4.1 中,我使用“%”作为通配符。

message: %hibernate3%
Run Code Online (Sandbox Code Playgroud)


Ily*_*iev 5

message: *.hibernate3.*
Run Code Online (Sandbox Code Playgroud)

也有效(请注意,不需要引号)

  • 如果您的查询有空格怎么办?即 `message:*the Quick Brown Fox*` 不起作用,用双引号括起来也不起作用。像这样的基本搜索功能已经有半个世纪的历史了,奇怪的是,今天重新发明这个轮子会导致一个劣质的轮子。 (5认同)
  • @JonathanNeufeld 说的话。让我大吃一惊的是,Kibana 缺少一些基本的文本查询功能。 (2认同)