【问题标题】:Azure Search Does Not Remove Data After Indexer RUN索引器运行后 Azure 搜索不删除数据
【发布时间】:2019-05-08 06:21:43
【问题描述】:

我在 blob 存储中有一个文件 folder/new/data1.json

data1 包含 json 数组。

[   
    {
        "name": "na",
        "data": {
            "1":"something1",
            "2":"something2"

        }
    },
    {
        "name": "ha",
        "data": {
            "1":"something1",
            "2":"something2"
        }
    }
]

我的数据源正文:

{
    "name" : "datasource",
    "type" : "azureblob",
    "credentials" : { "connectionString" : "MyStorageConnStrning" },
    "container" : { "name" : "mycontaner", "query" : "folder/new" }
}   

我的索引正文:

{
    "name" : "index",
    "fields": [
       { "name": "id", "type": "Edm.String", "key": true, "searchable": false },
       { "name": "name", "type": "Edm.String", "searchable": true, "filterable": false, "sortable": true, "facetable": true},
       { "name": "data", "type": "Edm.String", "searchable": false}
    ]
}

索引器主体:

{
    "name" : "indexer",
    "dataSourceName" : "datasource",
    "targetIndexName" : "index",
    "parameters" : { "configuration" : { "parsingMode" : "jsonArray" } }
}

创建后我可以搜索naha 并获得结果。

但如果我从 blob 存储中删除 folder/new/data1.json 并运行索引器并尝试搜索 naha 我仍然会得到结果。

我发现如果我删除索引器并重新创建它,naha 将不再搜索。

有什么方法可以在不删除索引器的情况下删除以前的数据?

【问题讨论】:

标签: azure azure-cognitive-search


【解决方案1】:

使用索引器删除文档有点棘手,尤其是当您的 blob 包含多个文档时;如果直接删除 blob,则索引器将看不到 blob,也不会尝试从索引中删除任何内容。

要让索引器删除你需要使用soft delete deletion detection policy的文档,例如:

{
  "@odata.type": "#Microsoft.Azure.Search.SoftDeleteColumnDeletionDetectionPolicy",
  "softDeleteColumnName": "IsDeleted",
  "softDeleteMarkerValue": "true"
}

当您要删除文档时,将"IsDeleted": true 添加到 JSON 对象。在 blob 中的所有文档都被软删除后并且索引器已拾取删除,然后您才能执行硬删除并删除 blob。

这里的一个微妙之处是您不得添加/删除/重新排列数组元素,因为您使用的是默认文档 ID,这取决于 blob 路径和数组索引。如果您使用 name 字段作为键,那么您将可以灵活地在 blob 内执行部分硬删除。

【讨论】:

    【解决方案2】:

    恐怕您需要自己从索引中删除条目。 查看Add, Update or Delete Documents (Azure Search Service REST API),了解如何使用Postman 之类的工具使用HTTP 请求来完成。

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 2019-07-24
      • 2019-02-14
      • 2021-05-28
      • 1970-01-01
      • 1970-01-01
      • 2016-07-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-05
      相关资源
      最近更新 更多