Elasticsearch NEST 2.0 unable to delete object by ID
<p>I'm unable to delete an object from an index by its ID.  I've tried solutions in the following:</p>

<ul>
<li><a href="https://stackoverflow.com/questions/26917221/elasticsearch-and-nest-how-do-you-purge-all-documents-from-an-index">ElasticSearch and NEST: How do you purge all documents from an index?</a></li>
<li><a href="https://www.elastic.co/guide/en/elasticsearch/client/net-api/1.x/delete-by-query.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/client/net-api/1.x/delete-by-query.html</a></li>
<li><a href="https://stackoverflow.com/questions/23791636/delete-a-document-from-elasticsearch-index-by-id">Delete a document from ElasticSearch index by id</a></li>
</ul>

<p>And they produce a variety of failures or inability to compile which I'm unable to resolve.</p>

<p>Simple example:</p>

<pre><code>public class Doc
{
    public int DocID;
    public string Name;
}

static void Main(string[] args)
{
    try
    {
        string indexName = "idx";
        Uri uri = new Uri("http://localhost:9200");
        ConnectionSettings settings = new ConnectionSettings(uri);
        ElasticClient client = new ElasticClient(settings);
        client.CreateIndex(indexName);

        Doc d1 = new Doc();
        d1.DocID = 1;
        d1.Name = "foo";

        Doc d2 = new Doc();
        d2.DocID = 2;
        d2.Name = "bar";

        var d1add = client.Index(d1, i =&gt; i.Index(indexName).Type(typeof(Doc)).Id(d1.DocID));
        Console.WriteLine("D1 Add Response: " + d1add);
        var d2add = client.Index(d2, i =&gt; i.Index(indexName).Type(typeof(Doc)).Id(d2.DocID));
        Console.WriteLine("D2 Add Response: " + d2add);

        // 
        // I will try a variety of delete operations here...
        //

        var d1remove = client.Delete&lt;Doc&gt;(d1.DocID);

        Console.WriteLine("D1 Reove Response: " + d1remove);
    }
    catch (Exception e)
    {
        PrintException(e);
    }
}
</code></pre>

<p>Produces the following output:</p>

<pre><code>D1 Add Response: Valid NEST response built from a successful low level call on PUT: /idx/doc/1
D2 Add Response: Valid NEST response built from a successful low level call on PUT: /idx/doc/2
================================================================================
 = Exception Type: System.ArgumentException
 = Exception Data: System.Collections.ListDictionaryInternal
 = Inner Exception:
 = Exception Message: Dispatching Delete() from NEST into to Elasticsearch.NET failed
Received a request marked as DELETE
This endpoint accepts DELETE
The request might not have enough information provided to make any of these endpoints:
  - /{index=&lt;NULL&gt;}/{type=doc}/{id=1}

 = Exception Source: Nest
 = Exception StackTrace:    at Nest.LowLevelDispatch.DeleteDispatch[T](IRequest`1 p) in C:\Users\russ\source\elasticsearch-net-2.x\src\Nest\_Generated\_LowLevelDispatch.generated.cs:line 734
   at Nest.ElasticClient.&lt;Delete&gt;b__193_0(IDeleteRequest p, PostData`1 d) in C:\Users\russ\source\elasticsearch-net-2.x\src\Nest\Document\Single\Delete\ElasticClient-Delete.cs:line 48
   at Nest.ElasticClient.Nest.IHighLevelToLowLevelDispatcher.Dispatch[TRequest,TQueryString,TResponse](TRequest request, Func`3 responseGenerator, Func`3 dispatch) in C:\Users\russ\source\elasticsearch-net-2.x\src\Nest\ElasticClient.cs:line 56
   at Nest.ElasticClient.Nest.IHighLevelToLowLevelDispatcher.Dispatch[TRequest,TQueryString,TResponse](TRequest request, Func`3 dispatch) in C:\Users\russ\source\elasticsearch-net-2.x\src\Nest\ElasticClient.cs:line 46
   at Nest.ElasticClient.Delete(IDeleteRequest request) in C:\Users\russ\source\elasticsearch-net-2.x\src\Nest\Document\Single\Delete\ElasticClient-Delete.cs:line 46
   at Nest.ElasticClient.Delete[T](DocumentPath`1 document, Func`2 selector) in C:\Users\russ\source\elasticsearch-net-2.x\src\Nest\Document\Single\Delete\ElasticClient-Delete.cs:line 42
   at ElasticSearchCLI.Program.Main(String[] args) in D:\code\test\ElasticSearchCLI\ElasticSearchCLI\Program.cs:line 52
</code></pre>

<p>When I replace the code in question with:</p>

<pre><code>var d1remove = client.DeleteByQuery&lt;Doc&gt;(q =&gt; q.Indices(new[] { indexName }).Query(rq =&gt; rq.Term(f =&gt; f.DocID, idval)));
</code></pre>

<p>It won't compile; I'm given the warning of:</p>

<pre><code>There is no argument given that corresponds to the required formal parameter 'types' of 'ElasticClient.DeleteByQuery&lt;T&gt;(Indices, Types, Func&lt;DeleteByQueryDescriptor&lt;T&gt;, IDeleteByQueryRequest&gt;)'
</code></pre>

<p>When I change the code in question to:</p>

<pre><code>var d1remove = client.Delete&lt;Doc&gt;(d =&gt; d.Id(d1.DocID).Index(indexName));
</code></pre>

<p>It also gives an error:</p>

<pre><code>Error   CS1660  Cannot convert lambda expression to type 'DocumentPath&lt;Program.Doc&gt;' because it is not a delegate type  ElasticSearchCLI    D:\code\test\ElasticSearchCLI\ElasticSearchCLI\Program.cs
</code></pre>

<p>Finally when I try:</p>

<pre><code>QueryContainer qcremove = null;
qcremove &amp;= new TermQuery { Field = "DocID", Value = d1.DocID};
var deleteRequest = new DeleteByQueryRequest(Indices.Parse(indexName), Types.Parse("Doc"));
deleteRequest.Query = qcremove;
var d1remove = client.DeleteByQuery(deleteRequest);
</code></pre>

<p>It compiles, but gives the following error when run:</p>

<pre><code>D1 Add Response: Valid NEST response built from a successful low level call on PUT: /idx/doc/1
D2 Add Response: Valid NEST response built from a successful low level call on PUT: /idx/doc/2
D1 Remove Response: Invalid NEST response built from a unsuccessful low level call on DELETE: /idx/Doc/_query
</code></pre>

<p>Any help?  Thanks!</p>