无法检索到包含Kibana中特定符号的数据。

问题描述 投票:0回答:1

我试着用Kibana来检索评论数据,其中包括一些特定的符号,如 它们不是一般的符号。

我尽量使用转义字符 \ 对他们来说,KQL就像 comment:\?comment:\\?我想用Kibana来恢复评论数据,其中包括一些特定的符号,如?和。

sql elasticsearch kibana kql
1个回答
1
投票

当你创建一个样本文档,让ES自动为你生成映射。

POST comments/_doc
{
  "comment": "?"
}

运转

GET comments/_mapping

会让你

"comment":{
  "type":"text",
  "fields":{
    "keyword":{
      "type":"keyword",
      "ignore_above":256
    }
  }
}

现在... text 类型的 分析器 通常是 standard 的默认值。

当我们试图查看我们的非标准字符是如何被分析出来的时候

GET comments/_analyze
{
  "text": "?",
  "analyzer": "standard"
}

结果是

{
  "tokens" : [ ]
}

意味着我们不能用标准分析的方式搜索其内容。text 领域,但需要

  1. 或者定义一个不同的默认分析器

  2. 或在评论中定义这个分析器。fields

采用第2种方法(因为将不同分析的字段分开是个好做法)。

PUT comments2
{
  "mappings": {
    "properties": {
      "comment": {
        "type": "text",
        "fields": {
          "whitespace_analyzed": {
            "type": "text",
            "analyzer": "whitespace"
          }
        }
      }
    }
  }
}

POST comments2/_doc
{
  "comment": "?"
}

经核实

GET comments2/_analyze
{
  "text": "?",
  "analyzer": "whitespace"
}

我们可以在KQL中做如下操作

comment.whitespace_analyzed:"?"

请注意,有一堆 内置分析仪 但也欢迎你创造自己的作品。

© www.soinside.com 2019 - 2024. All rights reserved.