我有一个想要标记的关键字字段(以逗号分隔),但它也可能包含带有“+”字符的值。例如:
query_string.keywords = Living,Music,+concerts+and+live+bands,News,Portland
创建索引时,以下内容可以很好地以逗号分隔关键字:
{
"settings": {
"number_of_shards": 5,
"analysis": {
"analyzer": {
"happy_tokens": {
"type": "pattern",
"pattern": "([,]+)"
}
}
}
},
"mappings": {
"post" : {
"properties" : {
"query_string.keywords" : {
"type": "string",
"analyzer" : "happy_tokens"
}
}
}
}
}
如何添加 char_filter(见下文)以将 + 更改为空格或空字符串?
"char_filter": {
"kill_pluses": {
"type": "pattern_replace",
"pattern": "+",
"replace": ""
}
}
最佳答案
我发现了“映射”char_filter
,它可以将我的加号字符转换为空格。标记化后,我能够修剪
标记以删除空格。
custom analyzers page in the elasticsearch guide是一个很大的帮助。
我的工作示例如下:
{
"settings": {
"number_of_shards": 5,
"index": {
"analysis": {
"char_filter": {
"plus_to_space": {
"type": "mapping",
"mappings": ["+=>\\u0020"]
}
},
"tokenizer": {
"split_on_comma": {
"type": "pattern",
"pattern": "([,]+)"
}
},
"analyzer": {
"happy_tokens": {
"type": "custom",
"char_filter": ["plus_to_space"],
"tokenizer": "split_on_comma",
"filter": ["trim"]
}
}
}
}
},
"mappings": {
"post" : {
"properties" : {
"query_string.keywords" : {
"type": "string",
"analyzer" : "happy_tokens"
}
}
}
}
}
关于elasticsearch - 如何在elasticsearch中结合模式分析器和char_filter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29546816/