在elasticsearch中,我尝试在一个字段上使用分析器,该分析器将使用过滤器替换?后的所有字符。遇到空格。为此,我正在使用以下过滤器。
"filter_name":{
"type": "pattern_replace",
"pattern": "\\?(.*)",
"replacement": ""
}
但这不能按预期工作。有什么我想念的吗?
答案 0 :(得分:0)
使用模式:"(?<=\\?)(.*)"
和替换项:""
答案 1 :(得分:0)
请参阅以下内容。我创建了一个示例映射和一个示例_analyze
查询,以了解如何创建令牌。
PUT my_index
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "standard",
"char_filter": [
"my_char_filter"
]
}
},
"char_filter": {
"my_char_filter": {
"type": "pattern_replace",
"pattern": "(?=.*)\\?(.*)",
"replacement": ""
}
}
}
}
}
POST my_index/_analyze
{
"analyzer": "my_analyzer",
"text": "Do you know? Life is crazy"
}
{
"tokens": [
{
"token": "Do",
"start_offset": 0,
"end_offset": 2,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "you",
"start_offset": 3,
"end_offset": 6,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "know",
"start_offset": 7,
"end_offset": 26,
"type": "<ALPHANUM>",
"position": 2
}
]
}
希望这会有所帮助!