简体   繁体   English

即使从数组中删除元素后,Vespa 搜索查询(在数组上)也会产生命中

[英]Vespa search query (on array) gives hits even after removing the element from array

I am querying vespa to check if a particular userId is present in an array of userIds.我正在查询 vespa 以检查特定用户 ID 是否存在于用户 ID 数组中。 http://localhost:8080/search/?yql=select * from sources doc where userIds contains 'user1';

Search Definition:搜索定义:

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

Sample Response:示例响应:

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

When I remove an element (" user1 ") from the array, I am still getting the hits in response, even when it is being succesfully removed from the array.当我从数组中删除一个元素(“ user1 ”)时,即使它已成功从数组中删除,我仍然收到响应。

Update API:更新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"
    }
}

Even after the above userIds field is updated, the same query即使上面的 userIds 字段更新后,同样的查询

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

gives the response,给出回应,

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

In the above respone, there is no " user1 " in the userIds array of " id:doc:doc::0 ".在上面的响应中,“ id:doc:doc::0 ”的 userIds 数组中没有“ user1 ”。 But, still the query gives it as a hit.但是,查询仍然将其作为命中。 Please help.请帮忙。

Edit-1: Note that, when I assign a new array with the element removed, it works correctly编辑 1:请注意,当我分配一个删除元素的新数组时,它可以正常工作

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

The above Update API gives the expected hits in response, for the query.上面的更新 API 为查询提供了预期的命中响应。 But, as I am calling the Update API from within a Searcher, I am getting a huge response time lag.但是,当我从 Searcher 中调用 Update API 时,出现了巨大的响应时间滞后。 (To create a new Array Object and assign to the userIds field, as the array grows to a big size of about 50000) (创建一个新的数组对象并分配给 userIds 字段,随着数组增长到大约 50000 的大大小)

Please, tell me why the remove option is failing.请告诉我为什么删除选项失败。 I really need to improve the query performance, by using it.我真的需要通过使用它来提高查询性能。

Edit-2: The following syntax, mentioning the element to be removed for updating the array works correctly.编辑 2:以下语法,提到要删除以更新数组的元素工作正常。 Thanks to @Jo's comment.感谢@Jo 的评论。

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

Note that the above syntax removes all the occurrences of the element specified.请注意,上述语法删除了所有出现的指定元素。

(Summary of the discussion above to provide an answer for the record) (以上讨论的总结,为记录提供答案)

Removing array elements by index is not supported, use remove by value instead:不支持按索引删除数组元素,请改用按值删除:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM