我正在尝试创建一个分析器,该分析器将删除(或替换为空白/空白)文档中带引号的句子。
如:this is my \"test document\"
例如,我希望术语“ vector ”为:[this, is, my]
最佳答案
Daniel Answer是正确的,但是由于缺少相应的正则表达式和替换,我提供了它,其中包括对文本的测试。
索引设置如下,使用模式替换字符。
{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "standard",
"char_filter": [
"my_char_filter"
],
"filter": [
"lowercase"
]
}
},
"char_filter": {
"my_char_filter": {
"type": "pattern_replace",
"pattern": "\"(.*?)\"",
"replacement": ""
}
}
}
}
}
之后,使用analyze API生成以下 token :
POST _analyze
{
"text": "this is my \"test document\"",
"analyzer" : "my_analyzer"
}
以上API的输出:
{
"tokens": [
{
"token": "this",
"start_offset": 0,
"end_offset": 4,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "is",
"start_offset": 5,
"end_offset": 7,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "my",
"start_offset": 8,
"end_offset": 10,
"type": "<ALPHANUM>",
"position": 2
}
]
}
关于elasticsearch - Elasticsearch Analyzer删除引用的句子,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60479170/