特殊文字を空白に置き換えて大文字に変換するアナライザーを作成しようとしています。その後、小文字で検索したい場合も機能するはずです。
マッピング アナライザー:
soundarya@soundarya-VirtualBox:~/Downloads/elasticsearch-2.4.0/bin$ curl -XPUT 'http://localhost:9200/aida' -d '{
"settings": {
"analysis": {
"analyzer": {
"my_analyzer": {
"tokenizer": "standard",
"char_filter": [
"my_char_filter"
],
"filter": [
"uppercase"
]
}
},
"char_filter": {
"my_char_filter": {
"type": "pattern_replace",
"pattern": "(\\d+)-(?=\\d)",
"replacement": "$1 "
}
}
}
}
}
'
{"acknowledged":true}
soundarya@soundarya-VirtualBox:~/Downloads/elasticsearch-2.4.0/bin$ curl -XPOST 'http://localhost:9200/aida/_analyze?pretty' -d '{
"analyzer":"my_analyzer",
"text":"My name is Soun*arya?jwnne&yuuk"
}'
特殊文字を空白に置き換えることで、単語を適切にトークン化しています。テキストから単語を検索しても、結果が得られません。
soundarya@soundarya-VirtualBox:~/Downloads/elasticsearch-2.4.0/bin$ curl -XGET 'http://localhost:9200/aida/_search' -d '{
"query":{
"match":{
"text":"My"
}
}
}'
上記の GET クエリから結果が得られません。次のような結果を得る:
soundarya@soundarya-VirtualBox:~/Downloads/elasticsearch-2.4.0/bin$ curl -XGET 'http://localhost:9200/aida/_search' -d '{
"query":{
"match":{
"text":"my"
}
}
}'
{"took":5,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}
誰でもこれで私を助けることができます! ありがとうございました!