gpt4 book ai didi

elasticsearch - 对 Elasticsearch 类型的所有字段使用 Completion Suggester

转载 作者:行者123 更新时间:2023-12-03 01:30:59 25 4
gpt4 key购买 nike

我正在实现 完成建议 在我的应用程序中,这是我的要求:

我正在使用 Elasticsearch 5.5.3(支持多种类型)。我的 Elasticsearch 中有大约 10 种类型,每种类型都有大约 10 个字符串字段。我想要做的是制作一个搜索框,当用户开始使用完成提示器输入时,它将完成短语(这 10 种类型的任何字段)。最好的方法是什么?正在使用 _全部领域一个好主意?

最佳答案

是的,使用 "custom all field" 是完全可行的。 completion 类型的字段

首先,使用所有类型创建索引并确保 copy completion 类型的自定义字段中的每个字段:

PUT my_index
{
"mappings": {
"type1": {
"properties": {
"field1": {
"type": "text",
"copy_to": "my_all"
},
"field2": {
"type": "text",
"copy_to": "my_all"
},
"my_all": {
"type": "completion"
}
}
},
"type1": {
"properties": {
"field1": {
"type": "text",
"copy_to": "my_all"
},
"field2": {
"type": "text",
"copy_to": "my_all"
},
"my_all": {
"type": "completion"
}
}
}
}
}

然后,您将像这样查询完成数据(即,不指定任何映射类型并使用常见的 my_all 字段):
POST my_index/_search
{
"suggest": {
"my-suggest": {
"prefix": "bla",
"completion": {
"field": "my_all"
}
}
}
}

关于elasticsearch - 对 Elasticsearch 类型的所有字段使用 Completion Suggester,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55960218/

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