如何用[]搜索字符串

时间:2018-07-12 21:07:17

标签: elasticsearch kibana

kibana中,如何搜索包含字符串MESSAGES的所有[]

如果我使用"hostname []"进行搜索,则它与完整的MESSAGE有效载荷匹配,如下图所示,但是如何匹配包含空[]的所有记录而忽略了hostname [3]这样的字段但包括foo bar hostname []之类的条目吗?

enter image description here

1 个答案:

答案 0 :(得分:0)

标准令牌生成器会在遇到空格或标点符号时将单词拆分(不包括特殊字符),您可以查看elasticsearch的分析方式:

GET _analyze
{
  "analyzer" : "standard",
  "text" : "function []"
}

{
  "tokens": [
    {
      "token": "function",
      "start_offset": 0,
      "end_offset": 8,
      "type": "<ALPHANUM>",
      "position": 0
    }
  ]
}

不包括[],现在可以使用whitespace分析器进行测试

GET _analyze
{
  "analyzer" : "whitespace",
  "text" : "function []"
}
{
  "tokens": [
    {
      "token": "function",
      "start_offset": 0,
      "end_offset": 8,
      "type": "word",
      "position": 0
    },
    {
      "token": "[]",
      "start_offset": 9,
      "end_offset": 11,
      "type": "word",
      "position": 1
    }
  ]
}

因此,对于这种特殊情况,只需更改映射即可,并在whitespace分析器字段中进行设置:

 "MESSAGE": {
    "type": "text",
    "analyzer" : "whitespace"
 }

enter image description here