Elasticsearch查询字符串过滤模式
我想使用Elasticsearch查询查询过滤以下文档,
{
"_index" : "logs-000001",
"_type" : "_doc",
"_id" : "GkA5koEBhT9d1rYBb7_e",
"_score" : null,
"_source" : {
"timestamp" : 1656015577105,
"message" : "2022-06-23 20:19:37 +0000 [info]: #0 Faraday error: logs.input.app1-7594a7072372481283701560b4efc07:578087ee41d47354bae68162e1490c434fcb68631eb42a6c2fae953aaae61831",
"ingestionTime" : 1656015581351,
"eventId" : "36930381429816247681747540585230094267893920556028395521",
"logGroup" : "logs-release200",
"logStream" : "logs/kinesis/964da56be54b47fda012669544502f4b"
}
}
到目前为止我想出的是
GET logs/_search
{
"sort": [
{
"timestamp": {
"order": "desc"
}
}
],
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "message",
"query": "*[info]: #0 Faraday error:*"
}
}
]
}
}
我要过滤特定消息模式的查询字符串。我还带来了与模式不匹配的其他记录。不胜感激地完善查询的任何帮助。 tia
I want to filter documents of the below kind with a elasticsearch query
{
"_index" : "logs-000001",
"_type" : "_doc",
"_id" : "GkA5koEBhT9d1rYBb7_e",
"_score" : null,
"_source" : {
"timestamp" : 1656015577105,
"message" : "2022-06-23 20:19:37 +0000 [info]: #0 Faraday error: logs.input.app1-7594a7072372481283701560b4efc07:578087ee41d47354bae68162e1490c434fcb68631eb42a6c2fae953aaae61831",
"ingestionTime" : 1656015581351,
"eventId" : "36930381429816247681747540585230094267893920556028395521",
"logGroup" : "logs-release200",
"logStream" : "logs/kinesis/964da56be54b47fda012669544502f4b"
}
}
Query I have come up with so far
GET logs/_search
{
"sort": [
{
"timestamp": {
"order": "desc"
}
}
],
"query": {
"bool": {
"must": [
{
"query_string": {
"default_field": "message",
"query": "*[info]: #0 Faraday error:*"
}
}
]
}
}
I want to filter the query string for the particular message pattern. The query I have also brings other records that do not match the pattern. Any help in refining the query is appreciated. TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
match_phrase
elasticsearch查询在[info]中获取结果:#0 faraday错误:
在消息字段中匹配。请注意,我从查询的启动和结尾删除了
*
。You can use
match_phrase
query of Elasticsearch for getting result where[info]: #0 Faraday error:
match in message field.Please note that i have removed
*
from start and end of your query.您可以尝试使用 - 它不使用分析仪,因此应正确匹配您
query_string is searching the fields using an analyzer, this is why you will have results that have partial match for any of the words. Also it ignores white spaces and some special symbols for the same reason - they are used to split the searched string into list of words to search for.
You could try using regex - it does not use analyzer so it should match your regex correctly