gpt4 book ai didi

arrays - Vespa 搜索查询(在数组上)即使在从数组中删除元素后也会给出命中

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

我正在查询 vespa 以检查某个特定的 userId 是否存在于 userIds 数组中。http://localhost:8080/search/?yql=select * from sources doc where userIds contains 'user1';

搜索定义:

search doc {
document doc {
field userIds type array<string> {
indexing : index | summary
}
field doctype type string {
indexing : summary
}
}

示例响应:

{
"children": [{
"id": "id:doc:doc::0",
"fields": {
"userIds": ["user1", "user2", "user3"],
"doctype": "type1"
}
},
{
"id": "id:doc:doc::1",
"fields": {
"userIds": ["user1", "user3"],
"doctype": "type2"
}
}
]}

当我从数组中删除一个元素 ("user1") 时,我仍然得到响应响应,即使它已从数组中成功删除 .

更新 API:

PUT http://localhost:8080/document/v1/doc/doc/docid/0
{
"update": "id:doc:doc::0",
"fields": {
"userIds[0]": {
"remove": 0
}
}
}

GET http://localhost:8080/document/v1/doc/doc/docid/0
{"fields": {
"userIds": ["user2", "user3"],
"doctype": "type1"
}
}

即使更新了上面的 userIds 字段之后,同样的查询

http://localhost:8080/search/?yql=select * from sources doc where userIds contains 'user1';

给出响应,

{"children": [{
"id": "id:doc:doc::0",
"fields": {
"userIds": ["user2", "user3"],
"doctype": "type1"
}
},
{
"id": "id:doc:doc::1",
"fields": {
"userIds": ["user1", "user3"],
"doctype": "type2"
}
}]}

在上面的响应中,“id:doc:doc::0”的userIds数组中没有“user1”。但是,查询仍然将其作为命中。请帮忙。

Edit-1:请注意,当我分配一个删除了元素的新数组时,它可以正常工作

PUT http://localhost:8080/document/v1/doc/doc/docid/0
{
"update": "id:doc:doc::0",
"fields": {
"userIds": {
"assign": ["user2", "user3"]
}
}
}

上面的 Update API 为查询提供了预期的响应响应。但是,当我从 Searcher 中调用 Update API 时,我遇到了巨大的响应时间滞后。 (创建一个新的 Array 对象并赋值给 userIds 字段,随着数组增长到大约 50000 的大尺寸)

请告诉我为什么删除选项失败。我真的需要通过使用它来提高查询性能。

Edit-2:以下语法,提及要删除以更新数组的元素,可以正常工作。感谢@Jo 的评论。

PUT http://localhost:8080/document/v1/doc/doc/docid/0
{
"update": "id:doc:doc::0",
"fields": {
"userIds": {
"remove": ["user1"]
}
}
}

请注意,上面的语法删除了所有出现的指定元素。

最佳答案

(上面的讨论总结提供答案备案)

不支持按索引删除数组元素,改为使用按值删除:

{
"update": "id:doc:doc::0",
"fields": {
"userIds": {
"remove": ["user1"]
}
}
}

关于arrays - Vespa 搜索查询(在数组上)即使在从数组中删除元素后也会给出命中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54361546/

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