我希望通过搜索希腊字母同义词(α为字母)来改善ES索引中的搜索。在这里,我希望通过搜索希腊字母的同义词(α为α)来改善ES索引的搜索效果。此职位 他们使用 "常规 "分析器,这将需要重新索引所有的数据。
我的问题是如何只使用search_analyzer来完成这个同义词搜索。
谢谢!下面是两个条目和搜索查询的例子。
这是一个关于两个条目和一个搜索查询的例子,我希望这个单一的查询能够同时返回两个docs
PUT test_ind/_doc/2
{
"title" : "α"
}
PUT test_ind/_doc/1
{
"title" : "alpha"
}
POST test_ind/_search
{
"query": {
"term": {
"title": "alpha"
}}
}
预期的输出。
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 2,
"max_score" : 1.0,
"hits" : [
{
"_index" : "test_ind",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"title" : "alpha"
}
},
{
"_index" : "test_ind",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"title" : "α"
}
}
]
}
}
PUT test_ind
{
"settings": {
"analysis": {
"analyzer": {
"synonyms": {
"tokenizer": "whitespace",
"filter": [
"synonym"
]
}
},
"filter": {
"synonym": {
"type": "synonym",
"synonyms": [
"α,alpha"
]
}
}
}
}
}
PUT test_ind/_doc/2
{
"title" : "α"
}
PUT test_ind/_doc/1
{
"title" : "alpha"
}
POST test_ind/_search
{
"query": {
"match": {
"title": {
"query": "alpha",
"analyzer": "synonyms"
}
}
}
}
如果你的索引已经存在,你需要添加分析器(不需要重新索引),如图所示。此处
POST /test_ind/_close
PUT /test_ind/_settings
{
"analysis": {
"analyzer": {
"synonyms": {
"tokenizer": "whitespace",
"filter": [
"synonym"
]
}
},
"filter": {
"synonym": {
"type": "synonym",
"synonyms": [
"α,alpha"
]
}
}
}
}
POST /test_ind/_open