如何使用"id"删除特定文档?在Azure搜索REST API上? [英] How to delete specific document using "id" on Azure Search REST API?
问题描述
我想知道如何删除Azure搜索索引中的特定文档.
I would like to know how to delete a specific document in an index of Azure Search.
我想使用"id"通过REST API删除文档.我已经搜索过,但找不到路.
I would like to use "id" to delete a document by using the REST API. I have searched, but couldn't find out the way.
{
"@odata.context": "https://xxxx/$metadata#docs(*)",
"value": [
{
"@search.score": 1,
"id": "16",
"questions": [
"Question"
],
"answer": "Answer",
"source": "https://azure.microsoft.com/ja-jp/support/faq/",
"keywords": [],
"alternateQuestions": null
},
例如,我只想删除ID为16的文档.我不想删除整个索引,只想删除文档.
For example, I would like to delete only the document whose id is 16. I don't want to delete whole index, just want to delete the document.
如果有人知道该怎么做,请提供一个REST API示例.
If someone knows how to do it, please provide a REST API sample.
推荐答案
The documentation for how to delete "documents" in Azure Search can be found here. Since you want to delete all of the fields associated with id == 16, this should be what you are looking for.
要针对您的具体情况更具体,您将需要对以下URI发出POST请求,并在其中填写适当的服务名称,索引名称和api管理密钥(作为标头):
To be more specific for your exact situation, you will want to issue a POST request to the following URI with the appropriate service name, index name and api admin key (as a header) filled in:
POST https://[service name].search.windows.net/indexes/[index name]/docs/index?api-version=2017-11-11
Content-Type: application/json
api-key: [admin key]
并带有以下请求正文:
{
"value": [
{
"@search.action": "delete",
"id": "16"
}
]
}
如果请求返回200,则该文档将成功从索引中删除.
If the request returns 200, then the document will have successfully been deleted from the index.
请注意,您可以通过在JSON数组中包含更多对象(每个对象具有不同的"id")来删除同一请求中的多个文档.这比一次将它们一次删除更为有效.
Note that you can delete more than one document in the same request by including more objects in the JSON array, each with a different "id". This is more efficient than deleting them one at a time.
这篇关于如何使用"id"删除特定文档?在Azure搜索REST API上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!