如何在 Kibana 中搜索带有特殊字符的单词 - Elasticsearch
How to search word with special characters in Kibana - Elasticsearch
有谁知道如何在消息中获取包含该值的值?如果我删除它搜索的 (-) 和 (/),如果我保留它们,查询不会 return 任何东西。
不是....
GET my-index/_search
{
"query": {
"wildcard" : {
"message": "*Z-01-123456-9/2020-1*"
}
}
}
不是....
GET my-index/_search
{
"query": {
"wildcard" : {
"message": "*Z\-01\-123456\-9\/2020\-1*"
}
}
}
映射:
{
"mappings": {
"properties": {
"message": {
"type": "keyword"
}
}
}
}
索引数据:
{
"message": "Z-01-123456-9/2020-1"
}
{
"message": "K-01-123456-9/2020-12"
}
{
"message": "Z-01-123456-9/2020-12"
}
搜索查询:
前提是有字段不解析。 "keyword" 类型的值未被分析,而是按原样编入索引。
{
"query": {
"wildcard" : {
"message": "*Z-01-123456-9/2020-1*"
}
}
}
搜索结果:
"hits": [
{
"_index": "test2",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": {
"message": "Z-01-123456-9/2020-1"
}
},
{
"_index": "test2",
"_type": "_doc",
"_id": "3",
"_score": 1.0,
"_source": {
"message": "Z-01-123456-9/2020-12"
}
}
]
您甚至可以使用模式替换过滤器和自定义分析器忽略查询中的特殊字符。
这是我的解决方案
GET my-index/_search
{
"query": {
"bool": {
"must": [
{
"match_phrase": {"message": "Z-01-123456-9/2020-1"}
},
{
"range": {
"@timestamp": {
"gte": "2020-06-16T07:00:00",
"lt": "2020-06-23T00:00:00"
}
}
}
]
}
}
}
有谁知道如何在消息中获取包含该值的值?如果我删除它搜索的 (-) 和 (/),如果我保留它们,查询不会 return 任何东西。
不是....
GET my-index/_search
{
"query": {
"wildcard" : {
"message": "*Z-01-123456-9/2020-1*"
}
}
}
不是....
GET my-index/_search
{
"query": {
"wildcard" : {
"message": "*Z\-01\-123456\-9\/2020\-1*"
}
}
}
映射:
{
"mappings": {
"properties": {
"message": {
"type": "keyword"
}
}
}
}
索引数据:
{
"message": "Z-01-123456-9/2020-1"
}
{
"message": "K-01-123456-9/2020-12"
}
{
"message": "Z-01-123456-9/2020-12"
}
搜索查询:
前提是有字段不解析。 "keyword" 类型的值未被分析,而是按原样编入索引。
{
"query": {
"wildcard" : {
"message": "*Z-01-123456-9/2020-1*"
}
}
}
搜索结果:
"hits": [
{
"_index": "test2",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": {
"message": "Z-01-123456-9/2020-1"
}
},
{
"_index": "test2",
"_type": "_doc",
"_id": "3",
"_score": 1.0,
"_source": {
"message": "Z-01-123456-9/2020-12"
}
}
]
您甚至可以使用模式替换过滤器和自定义分析器忽略查询中的特殊字符。
这是我的解决方案
GET my-index/_search
{
"query": {
"bool": {
"must": [
{
"match_phrase": {"message": "Z-01-123456-9/2020-1"}
},
{
"range": {
"@timestamp": {
"gte": "2020-06-16T07:00:00",
"lt": "2020-06-23T00:00:00"
}
}
}
]
}
}
}