Reputation: 4310
I'm trying to delete some documents from my Elasticsearch collection using NEST
The following code works and returns 3 docs:
var results = client.Search<JObject>(s => s.Query(q => q.Terms("string.ProgramId", ids))
But when I use same query with DeleteByQuery like this:
var response = client.DeleteByQuery<string>(s => s.Query(q => q.Terms("string.ProgramId", ids)));
It throws me the following error:
An unhandled exception of type 'Nest.DispatchException' occurred in Nest.dll
Additional information: Could not dispatch IElasticClient.DeleteByQuery() into any of the following paths:
- /{index}/_query
What am I doing wrong?
[edit]
Got a response to it at another site that I need to specify indices when using a destructive endpoint such as delete. And also that I need to specify either the same type in the search/delete for it to go to the same path when querying or specify AllTypes()
Tried the following line:
var response = client.DeleteByQuery<JObject>(s => s.AllIndices().Query(q => q.Terms("string.ProgramId", ids)));
And though it didn't throw an error this time, it didn't return any results.
Upvotes: 3
Views: 1380
Reputation: 4310
Came to the following conclusion:
You need to have the Search and DeleteByQuery to use the same type if you expect the same results.
Also, the Delete actually happened! but I was expecting response.Found to be true if it deleted anything, which didn't happen.
Should be fixed in NEST 2.0 (they pushed a fix following this issue)
So for now, you can use response.IsValid to validate it came ok (but perhaps not that it deleted anything)
Upvotes: 4