简体   繁体   中英

Dispatching Update() from NEST into to Elasticsearch.NET failed

I have upgraded to NEST 5.5.0:

I believe I am missing the parameter ID but how will I write it in my code:

  var response = client.Update<myOrder>(order, x => x.Parent(order.Id));

Error encountered: {"Dispatching Update() from NEST into to Elasticsearch.NET failed\\r\\nReceived a request marked as POST\\r\\nThis endpoint accepts POST\\r\\nThe request might not have enough information provided to make any of these endpoints:\\r\\n - /{index=orders}/{type=order}/{id=}/_update\\r\\n"}

Is there another way I could write this code?

Yes, most probably you are missing Elastic document ID in your object.

Try to retrieve the object first from your index and get the Elastic Doc ID from it if you don't have it already.

var response = client.Search<myOrder>(p => p
            .Size(1)
            .Query(q => q
                .Match(m => m
                    .Field(f => f.OrderID)
                    .Query("your order id")
            )));

var ElasticOrderID = response.Hits.FirstOrDefault()?.Id ?? string.Empty;

then do update with the ID..

var response = client.Update<myOrder>(ElasticOrderID , x => x.Parent(order.Id));

OR

you can have a field for ElasticDocID in your object and update with the object as it will use the ID from the object while updating..

var response = client.Update<myOrder>(myOrder, x => x.Parent(order.Id));

Actually for Nest 6+ it's:

var response = await client.UpdateAsync<myOrder, dynamic>(new DocumentPath<myOrder>(order.Id), 
    u => u.Index(indexName).Doc(order));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM