我尝试使用Kibana检索评论数据,其中包括一些特定符号,例如?
和。
,它们不是通用符号。
我尝试为他们使用转义字符\
,KQL类似于comment:\?
或comment:\\?
,但是它不起作用,有人可以帮忙吗?
答案 0 :(得分:1)
创建示例文档并让ES为您自动生成映射时,
POST comments/_doc
{
"comment": "?"
}
运行
GET comments/_mapping
会帮助您
"comment":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
}
现在,text
类型的analyzer通常默认为standard
。
当我们尝试查看如何分析非标准字符时
GET comments/_analyze
{
"text": "?",
"analyzer": "standard"
}
结果是
{
"tokens" : [ ]
}
表示我们无法使用经过标准分析的text
字段来搜索其内容,但需要
要么定义其他默认分析器
或在评论的fields
采用第二种方法(因为分开进行不同分析的字段是一种很好的做法),
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:"?"
请注意,有一堆built-in analyzers供您选择,但我们非常欢迎您创建自己的。