Elasticsearch char_filter不影响搜索



我对char_filter工作原理的理解肯定是错误的。我的目标是在弹性搜索中对所有撇号和类似引号的字符一视同仁(在本例中,完全删除它们(。(显然有5个类似撇号的unicode字符……我的数据库有所有版本:facepalm:(

旁白:这种解决方案的方法受到了这个线程的启发

这是一个玩具问题,说明了我的问题。我用char_filter创建了一个索引,然后用3个文档填充它:

PUT test
{
"settings": {
"analysis": {
"analyzer": {
"quote_analyzer": {
"char_filter": [
"quotes"
],
"tokenizer": "standard"
}
},
"char_filter": {
"quotes": {
"mappings": [
"u0091=>",
"u0092=>",
"u2018=>",
"u2019=>"
],
"type": "mapping"
}
}
}
}
}
POST test/_doc
{
"name": "The King’s men",
"id": "1"
}
POST test/_doc
{
"name": "Zoom LeBron the Soldier 7 'King's Pride'",
"id": "2"
}
POST test/_doc
{
"name": "Kings Kings Kings",
"id": "3"
}

正如您所看到的,每个文档都包含某种形式的单词Kings。然后我检查我的分析器是否在做我认为应该做的事情:

GET test/_analyze
{
"analyzer": "quote_analyzer",
"text": "King’s boat"
}

哪个收益率:

{
"tokens" : [
{
"token" : "Kings",
"start_offset" : 0,
"end_offset" : 6,
"type" : "<ALPHANUM>",
"position" : 0
},
{
"token" : "boat",
"start_offset" : 7,
"end_offset" : 11,
"type" : "<ALPHANUM>",
"position" : 1
}
]
}

看起来King’s中的撇号已被删除,标记为Kings。太棒了所以现在我想搜索King’s,由于分析器正在删除撇号,我应该会得到所有三个结果。或者,至少我只得到id:3,因为去掉了撇号,它只匹配没有撇号的Kings Kings Kings。但是,正在搜索:

GET test/_search 
{
"query": {
"match": {
"name": "King’s boat"
}
}
}

收益率:

{
"took" : 1,
// collapsing ....
"hits" : {
// collapsing ....
"hits" : [
{
"_index" : "test",
"_type" : "_doc",
"_id" : "1e2x_38Bn0QWlup8OIvp",
"_score" : 1.1220688,
"_source" : {
"name" : "The King’s men",
"id" : "1"
}
}
]
}
}

类似地,搜索Kings boat仅检索id:3。搜索CCD_ 9仅检索CCD_。

我错过了什么?如何实现对所有撇号字符一视同仁的目标?

请修改您的char_filter以同时包含引号和撇号,就像您对引号所做的那样。

最新更新