I've searched but can't find any tests demonstrating that the .NET Azure SDK for Azure Search supports deleting documents in the search service index.
Using Microsoft Azure Search Library 0.9.7-preview .
Intellisense in VS doesn't show any operation/method other than Create.
Was expecting IndexBatch.Delete to be able to state:
await indexClient.Documents.IndexAsync(IndexBatch.Delete(myDocs.Select(doc => IndexAction.Delete(doc))));
Yes. You can use IndexActionType.Delete for this:
var batch =
IndexBatch.Create(
new IndexAction(IndexActionType.Delete, new Document() { { "id", "123" } }),
new IndexAction(IndexActionType.Delete, new Document() { { "id", "456" } }),
new IndexAction(IndexActionType.Delete, new Document() { { "id", "789" } }));
indexClient.Documents.Index(batch);
Urm...... not with the latest version of the .sdk you can't!!! Might need to update the code snippet above to something like
IndexBatch.Delete(
new Document() { { "id", "123" } },
new Document() { { "id", "456" } },
new Document() { { "id", "789" } });
The answer was valid for the SDK version mentioned in the original issue. Then we changed the SDK to make things easier. :-)
Here is how you would delete a batch with version 1.0 or later:
var batch = IndexBatch.Delete("id", new[] { "123", "456", "789" });
indexClient.Documents.Index(batch);
Or, if you want to mix different operations in the same batch, you can do this:
var batch =
IndexBatch.New(new[] {
IndexAction.Delete("id", "123"),
IndexAction.Delete("id", "456"),
IndexAction.Delete("id", "789"),
/* Put IndexAction.Upload, Merge, or MergeOrUpload here */
});
indexClient.Documents.Index(batch);
Most helpful comment
The answer was valid for the SDK version mentioned in the original issue. Then we changed the SDK to make things easier. :-)
Here is how you would delete a batch with version 1.0 or later:
Or, if you want to mix different operations in the same batch, you can do this: