Я пытаюсь создать elasti c поисковый документ, который токенизирует данные определенным образом. Для такой строки, как Los Angeles (and vicinity), California, United States of America
, я хочу, чтобы такие символы, как ( ) ,
et c, были исключены и включались только буквенно-цифровые символы.
https://www.elastic.co/guide/en/elasticsearch/reference/7.x/analysis-keep-types-tokenfilter.html#analysis -keep-types-tokenfilter-customize
Мои настройки индекса ES выглядят следующим образом
PUT /test-index
{
"settings": {
"analysis": {
"filter": {
"extract_alpha": {
"type": "keep_types",
"mode": "include",
"types": [
"<ALPHANUM>"
]
}
},
"analyzer": {
"my_autocomplete": {
"type":"custom",
"tokenizer":"my_tokenizer",
"filter" : [
"lowercase",
"extract_alpha"
]
}
},
"tokenizer": {
"my_tokenizer" : {
"type": "whitespace"
}
}
}
},
"mappings": {
"properties": {
"name": {
"type": "text",
"analyzer": "my_autocomplete"
}
}
}
}
Однако при запуске этот запрос
GET test-index/_analyze
{
"analyzer": "my_autocomplete",
"text": "Los Angeles (and vicinity), California, United States of America"
}
Я получаю вывод
{
"tokens" : [ ]
}
Если я удаляю фильтр extract_alpha
, я получаю токены, но с включенными символами
{
"tokens" : [
{
"token" : "los",
"start_offset" : 0,
"end_offset" : 3,
"type" : "word",
"position" : 0
},
{
"token" : "angeles",
"start_offset" : 4,
"end_offset" : 11,
"type" : "word",
"position" : 1
},
{
"token" : "(and",
"start_offset" : 12,
"end_offset" : 16,
"type" : "word",
"position" : 2
},
{
"token" : "vicinity),",
"start_offset" : 17,
"end_offset" : 27,
"type" : "word",
"position" : 3
},
{
"token" : "california,",
"start_offset" : 28,
"end_offset" : 39,
"type" : "word",
"position" : 4
},
{
"token" : "united",
"start_offset" : 40,
"end_offset" : 46,
"type" : "word",
"position" : 5
},
{
"token" : "states",
"start_offset" : 47,
"end_offset" : 53,
"type" : "word",
"position" : 6
},
{
"token" : "of",
"start_offset" : 54,
"end_offset" : 56,
"type" : "word",
"position" : 7
},
{
"token" : "america",
"start_offset" : 57,
"end_offset" : 64,
"type" : "word",
"position" : 8
}
]
}
Как мне это исправить, что я делаю не так?