8

I'm having a little difficulty getting NEST's DeleteByQuery method to work.

Very simply the query never finds anything to delete, and I can't figure out why. I'm using the same query to return records (using Search) and everything works as expected.

    private void Delete(MyClass someObject)
    {
        var response = elasticClient.DeleteByQuery<MyClass>(q => q                
            .Match(m => m.OnField(f => f.Guid).Equals(someObject.Guid))            
            );
    }

I've only just started using NEST, so I'm sure this is a pretty simple problem and I'm just being a little dim!

Any help/suggestions much appreciated.

2 Answers 2

10

UPDATE NEST to version 6.4.0

var response = _client.DeleteByQuery<MyClass>(q => q
            .Query(rq => rq
                .Match(m => m
                .Field(f => f.Guid)
                .Query(guid.ToString())) 
            )
            .Index("Index_Name")
        );
Sign up to request clarification or add additional context in comments.

1 Comment

I thought I'd post the following adjustment to specify the index for good Abstraction practise; var response = _elasticClient.DeleteByQuery<DocumentData>(q => q .Query(rq => rq .Match(m => m .Field(f => f.DocumentID) .Query(documentID.ToString() )) ).Index(indexName) );
9

The .Equals() is a .NET method on Object that checks for equality.

If you change the call to Equals() to Query(someObject.Guid) it should work.

2 Comments

Thanks for the reply. I must be missing something because I can't swap out the call to Equals() to Query(someObject.Guid). Any chance you could give a quick example clarifying what you mean?
I think in the nuget version its still called QueryString()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.