有人知道我如何在消息中获取包含该值的值吗?如果删除(-)和(/),它将进行搜索;如果保留它们,则查询将不会返回任何内容。
不是。...
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*"
}
}
}
答案 0 :(得分:0)
映射:
{
"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"
}
搜索查询:
先决条件是不分析字段。不会对“关键字”类型的值进行分析,并对其进行索引。
{
"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"
}
}
]
您甚至可以使用模式替换过滤器和自定义分析器忽略查询中的特殊字符。
答案 1 :(得分:0)
这是我的解决方法
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"
}
}
}
]
}
}
}