[英]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.