Azure搜索返回已删除的blob资源的结果

问题描述 投票:3回答:2

我有一个Azure搜索服务,用于根据BLOB元数据搜索BLOBS(图像)。

搜索所基于的索引设置为每小时刷新一次。

但是我仍然在搜索结果中返回不再存在的BLOB结果。

使用Get Indexer Status API(下面的输出)显示删除BLOBS后索引已成功刷新。

"status": "running",
"lastResult": {
    "status": "success",
    "errorMessage": null,
    "startTime": "2018-02-05T16:00:03.29Z",
    "endTime": "2018-02-05T16:00:03.416Z",
    "errors": [],
    "warnings": [],
    "itemsProcessed": 0,
    "itemsFailed": 0,
    "initialTrackingState": "{\r\n  \"lastFullEnumerationStartTime\": \"2018-02-05T14:59:31.966Z\",\r\n  \"lastAttemptedEnumerationStartTime\": \"2018-02-05T14:59:31.966Z\",\r\n  \"nameHighWaterMark\": null\r\n}",
    "finalTrackingState": "{\"LastFullEnumerationStartTime\":\"2018-02-05T15:59:33.2900956+00:00\",\"LastAttemptedEnumerationStartTime\":\"2018-02-05T15:59:33.2900956+00:00\",\"NameHighWaterMark\":null}"
},
"

如果相关,则使用Azure Storage Explorer删除BLOB

这导致的问题是这些图像被输出到网页并且当前显示为丢失的图像以及使索引大于它需要的值。

azure azure-storage-blobs azure-search azure-blob-storage
2个回答
4
投票

经过一些阅读后,我发现Azure搜索目前支持的唯一删除策略是Soft Delete。

要为BLOB存储启用此功能,您必须在每个BLOB上创建元数据值(例如IsDeleted)并更新此值以使其能够被删除策略捕获。

PUT https://[service name].search.windows.net/datasources/blob-datasource?api-version=2016-09-01
Content-Type: application/json
api-key: [admin key]

{
"name" : "blob-datasource",
"type" : "azureblob",
"credentials" : { "connectionString" : "<your storage connection string>" },
"container" : { "name" : "my-container", "query" : "my-folder" },
"dataDeletionDetectionPolicy" : {
    "@odata.type" :"#Microsoft.Azure.Search.SoftDeleteColumnDeletionDetectionPolicy",     
    "softDeleteColumnName" : "IsDeleted",
    "softDeleteMarkerValue" : "true"
    }
} 

Full details here

我需要做一些测试,以确保更新元数据然后立即删除BLOB是安全的。


3
投票

虽然软删除是一个选项,但如果您愿意,也可以直接修改索引器所针对的索引。

您可以使用POST来索引API详细的on this page,以使用“key”字段直接删除文档。以下示例:

POST https://[service name].search.windows.net/indexes/[index name]/docs/index?api-version=[api-version]   
Content-Type: application/json   
api-key: [admin key]  
{  
  "value": [  
    {  
      "@search.action": "delete",  
      "key_field_name": "value"
    }
  ]  
} 

假设您没有使用字段映射来修改blob索引器的默认“键”行为,则从文档on this page开始,键字段将是metadata_storage_path属性的base64编码值(有关详细信息,请再次参阅上一个链接)。因此,在删除blob时,您可以编写一个触发器,将相应的有效负载PO​​ST到您希望从中删除文档的搜索索引。

© www.soinside.com 2019 - 2024. All rights reserved.