[英]Custom analyzer not working in elasticsearch
Running elastic version 1.6 运行弹性1.6版
I am trying to set custom analyzer for my index in elasticsearch. 我正在尝试为Elasticsearch中的索引设置自定义分析器。 My index /has some properties which contains some accents and special characters. 我的索引/具有一些包含某些重音符号和特殊字符的属性。
Like one of my property name has value like this, "name" => "Está loca" . 就像我的财产名称之一具有这样的值, “ name” =>“Estáloca” 。 So what I want to achieve is, whenever I am trying to search by this way, http://localhost:9200/tutorial/helloworld/_search?q=esta 所以我想要实现的是,每当我尝试通过这种方式进行搜索时, http:// localhost:9200 / tutorial / helloworld / _search?q = esta
I should get the result for "Está loca" . 我应该得到“Estáloca”的结果。 I have gone through following link and configured necessary analyzer which is explain in the link. 我已经通过以下链接并配置了必要的分析器,该分析器在该链接中进行了说明。 https://www.elastic.co/guide/en/elasticsearch/guide/current/asciifolding-token-filter.html 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" ]
}
}
}
}
}'
I have configured this while creating index and made some entries like this for test, 我在创建索引时进行了配置,并做了一些类似的测试项目,
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á!" }'
but while searching like this, http://localhost:9200/tutorial/helloworld/_search?q=esta nothing is happening. 但是在进行这样的搜索时, http:// localhost:9200 / tutorial / helloworld / _search?q = esta没有任何反应。 I just want whenever a user searches in any languages for example in English it should get the same result. 我只希望每当用户使用任何语言(例如英语)进行搜索时,它都应获得相同的结果。 Please anybody can help, how can I achieve this struggling on it for last 1 week. 请任何人都可以提供帮助,我如何才能在最近1周的时间内实现这一目标?
you would not be able to search for esta
keyword in _all
field. 您将无法在_all
字段中搜索esta
关键字。 As elasticsearch by default only apply standard analyzer while constructing _all
field . 默认情况下,由于_all
仅在构造_all
字段时应用标准分析器。
so your following query 所以你下面的查询
GET folding_index1/helloworld/_search?q=esta
Produces following match query in elastic dsl. 在弹性dsl中产生以下匹配查询。
GET folding_index1/helloworld/_search
{
"query": {
"match": {
"_all": "esta"
}
}
}
Which search against _all
field and hence couldn't find folded token for name. 该搜索针对_all
字段,因此找不到名称的折叠标记。
You can do following, but even with include_in_all
mentioned for multifield, it still applies standard analyzer for _all field. 您可以执行以下操作,但是即使对于多字段提到了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"]
}
}
}
}
}
Query like following can work for you. 如下查询可以为您服务。 More on _all field analyzer 有关_all现场分析仪的更多信息
POST folding_index1/_search?q=name.folded:esta
This link also helped me a lot, gives exact analyzer for my scenario. 该链接也为我提供了很多帮助,为我的方案提供了准确的分析器。
https://vanwilgenburg.wordpress.com/2013/08/03/diacritics-in-elasticsearch/ https://vanwilgenburg.wordpress.com/2013/08/03/diacritics-in-elasticsearch/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.