简体   繁体   English

将Update()从NEST分发到Elasticsearch.NET失败

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

I have upgraded to NEST 5.5.0: 我已升级到NEST 5.5.0:

I believe I am missing the parameter ID but how will I write it in my code: 我相信我缺少参数ID,但是如何在代码中编写它:

  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"} 遇到错误:{“将Update()从NEST分发到Elasticsearch.NET失败\\ r \\ n接收到标记为POST \\ r \\ n的请求此端点接受POST \\ r \\ n该请求可能没有提供足够的信息来构成任何这些端点:\\ 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. 是的,很可能您的对象中缺少弹性文档ID。

Try to retrieve the object first from your index and get the Elastic Doc ID from it if you don't have it already. 尝试首先从索引中检索对象,如果还没有,请从中获取Elastic Doc ID。

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.. 然后使用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.. 您可以在对象中有一个ElasticDocID字段,并使用该对象进行更新,因为它将在更新时使用来自该对象的ID。

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

Actually for Nest 6+ it's: 实际上,对于Nest 6+,它是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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