gpt4 book ai didi

elasticsearch - 如何在Elasticsearch中使用search_analyzer替换希腊字母同义词

转载 作者:行者123 更新时间:2023-12-02 23:45:05 28 4
gpt4 key购买 nike

我希望通过搜索希腊字母同义词(α为alpha)来改进ES索引中的搜索。在this post中,他们使用“常规”分析器,该分析器需要重新索引所有数据。

我的问题是如何仅使用search_analyzer完成此同义词搜索。

谢谢!

这是两个条目和一个搜索查询的示例,我希望这个查询返回两个文档

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"
}
}
}
}

并且如果您的索引已经存在,则需要添加分析器(无需重新索引),如图 here所示
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

关于elasticsearch - 如何在Elasticsearch中使用search_analyzer替换希腊字母同义词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61761287/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com