0

有谁知道我如何在消息中获取包含该值的值?如果我删除它搜索的 (-) 和 (/),如果我离开它们,则查询不会返回任何内容。

不是....

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*"
        }
    }
}
4

2 回答 2

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"
            }
          }
        }
      ]
    }
  }
}
于 2020-06-22T12:30:28.597 回答
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"
                }
            }
        ]

您甚至可以使用模式替换过滤器和自定义分析器忽略查询中的特殊字符。

于 2020-06-20T06:03:44.143 回答