[英]Custom analyzer not working in elasticsearch
運行彈性1.6版
我正在嘗試為Elasticsearch中的索引設置自定義分析器。 我的索引/具有一些包含某些重音符號和特殊字符的屬性。
就像我的財產名稱之一具有這樣的值, “ name” =>“Estáloca” 。 所以我想要實現的是,每當我嘗試通過這種方式進行搜索時, http:// localhost:9200 / tutorial / helloworld / _search?q = esta
我應該得到“Estáloca”的結果。 我已經通過以下鏈接並配置了必要的分析器,該分析器在該鏈接中進行了說明。 https://www.elastic.co/guide/zh-CN/elasticsearch/guide/current/asciifolding-token-filter.html
curl -XPUT 'localhost:9200/tutorial?pretty' -H 'Content-Type: application/json' -d'
{
"mappings":{
"helloworld":{
"properties": {
"name": {
"type": "string",
"analyzer": "standard",
"fields": {
"folded": {
"type": "string",
"analyzer": "folding"
}
}
}
}
}
},
"settings": {
"analysis": {
"analyzer": {
"folding": {
"tokenizer": "standard",
"filter": [ "lowercase", "asciifolding" ]
}
}
}
}
}'
我在創建索引時進行了配置,並做了一些類似的測試項目,
curl -X POST 'http://localhost:9200/tutorial/helloworld/1' -d '{ "name": "Está loca!" }'
curl -X POST 'http://localhost:9200/tutorial/helloworld/2' -d '{ "name": "Está locá!" }'
但是在進行這樣的搜索時, http:// localhost:9200 / tutorial / helloworld / _search?q = esta沒有任何反應。 我只希望每當用戶使用任何語言(例如英語)進行搜索時,它都應獲得相同的結果。 請任何人都可以提供幫助,我如何才能在最近1周的時間內實現這一目標?
您將無法在_all
字段中搜索esta
關鍵字。 默認情況下,由於_all
僅在構造_all
字段時應用標准分析器。
所以你下面的查詢
GET folding_index1/helloworld/_search?q=esta
在彈性dsl中產生以下匹配查詢。
GET folding_index1/helloworld/_search
{
"query": {
"match": {
"_all": "esta"
}
}
}
該搜索針對_all
字段,因此找不到名稱的折疊標記。
您可以執行以下操作,但是即使對於多字段提到了include_in_all
,它仍然對_all字段應用標准分析器。
PUT folding_index1
{
"mappings": {
"helloworld": {
"properties": {
"name": {
"type": "string",
"analyzer": "standard",
"fields": {
"folded": {
"type": "string",
"analyzer": "folding",
"include_in_all": true
}
}
}
}
}
},
"settings": {
"analysis": {
"analyzer": {
"folding": {
"tokenizer": "standard",
"filter": ["lowercase", "asciifolding"]
}
}
}
}
}
如下查詢可以為您服務。 有關_all現場分析儀的更多信息
POST folding_index1/_search?q=name.folded:esta
該鏈接也為我提供了很多幫助,為我的方案提供了准確的分析器。
https://vanwilgenburg.wordpress.com/2013/08/03/diacritics-in-elasticsearch/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.