2

I'm reindexing my index, but I've encountered a problem whenever I try to delete a non-existing document, so I need to check if the document already exists.

The approach is just explained in the elasticsearch docs.

I found a question with some interesting code, which I already tried

var docExists = client.DocumentExists<object>(d => d
    .Index(indexname)
    .Id(myId)
    .Type("Abcdef"));

But the compiler is giving an error

Cannot convert lambda expression to type 'Nest.DocumentPath<object>' because it's not a delegate type

I suppose my error comes because the question refers to NEST 1.x and I'm using NEST 2.x.

I know I can do a simple query, but I want to know if there is a direct way like ES doc-exists.

Thanks

Community
  • 1
  • 1
I.G. Pascual
  • 5,818
  • 5
  • 42
  • 58

2 Answers2

4

Signature of DocumentExists changed a little bit in NEST 2.x.

Right now it looks like:

public IExistsResponse DocumentExists<T>(DocumentPath<T> document, Func<DocumentExistsDescriptor<T>, IDocumentExistsRequest> selector = null) where T : class

Your example could be expressed as follows

client.DocumentExists<Document>(myId, d => d
    .Index(indexname)
    .Type("Abcdef"));

If you are curious about DocumentPath<T> please read this great peace of NEST docs.

Rob
  • 9,664
  • 3
  • 41
  • 43
  • Thanks! I ended up with this solution though `client.DocumentExists(new DocumentExistsRequest(indexName, type.Name, myId))`, as I couldn't use a generic method – I.G. Pascual Jun 02 '16 at 11:13
2

I ended up using

client.DocumentExists(new DocumentExistsRequest(indexName, type.Name, myId))

as I couldn't use the generic method DocumentExists<T>(..)

I.G. Pascual
  • 5,818
  • 5
  • 42
  • 58