Elasticsearch 匹配数组中的相似句子
Elasticsearch matching similar sentences in arrays
我正在使用 elasticsearch 构建一个聊天机器人,但我不知道如何让它按照我想要的方式运行。
我在索引“/questions/q”中有这种格式的问题对象:
{
"name": "some question" //just for identification,
"questions": [
"Is ice cream good?",
"Is ice cream delicious?",
"Will i love the taste of ice cream?"
],
"response": "yes"
}
我想将输入问题与问题数组进行匹配,其中得分最高的对象是具有最佳单个匹配问题的对象。所以基本上我希望对象的分数是它数组中最高问题的分数。
目前,我正在使用与此类似的查询:
{
"query": {
"match": {
"questions": {
"query": "where can i buy tickets"
}
}
}
}
但如果数组很大,它给我的分数很低,因为我猜它会将数组展平为一个大字符串。
对于这个用例,我应该使用哪种查询?
你应该使用嵌套数据类型,它既可以解决你的问题,又可以防止像 "is love good?" 这样的字符串匹配这个问题集 ?
在 https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html
查看原因和方法
我正在使用 elasticsearch 构建一个聊天机器人,但我不知道如何让它按照我想要的方式运行。
我在索引“/questions/q”中有这种格式的问题对象:
{
"name": "some question" //just for identification,
"questions": [
"Is ice cream good?",
"Is ice cream delicious?",
"Will i love the taste of ice cream?"
],
"response": "yes"
}
我想将输入问题与问题数组进行匹配,其中得分最高的对象是具有最佳单个匹配问题的对象。所以基本上我希望对象的分数是它数组中最高问题的分数。
目前,我正在使用与此类似的查询:
{
"query": {
"match": {
"questions": {
"query": "where can i buy tickets"
}
}
}
}
但如果数组很大,它给我的分数很低,因为我猜它会将数组展平为一个大字符串。
对于这个用例,我应该使用哪种查询?
你应该使用嵌套数据类型,它既可以解决你的问题,又可以防止像 "is love good?" 这样的字符串匹配这个问题集 ?
在 https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html
查看原因和方法