gpt4 book ai didi

elasticsearch - 包含空值后, Elasticsearch 更新失败

转载 作者:行者123 更新时间:2023-12-03 01:39:36 25 4
gpt4 key购买 nike

我们最近升级到了 Elasticsearch v5和nest v5.6

我们试图将字段设置为null,但是默认的序列化设置将忽略null值。

var pool = new SingleNodeConnectionPool(new Uri("http://local:9200"));

var connectionSettings =
new ConnectionSettings(pool)
.DisableDirectStreaming();

var elasticClient = new ElasticClient(connectionSettings);

var indexName = "myIndexName";
var typeName = "myTypeName";
var documentId = 2;

var pendingDescriptor = new BulkDescriptor();
pendingDescriptor.Index(indexName).Type(typeName);

var pendingUpdate = new Dictionary<string, object>
{
{ $"DocumentType_TAG_PENDING_Id", null }
};

var updateRequest = new UpdateRequest<dynamic, dynamic>(indexName, typeName, new Id(documentId));
updateRequest.Doc = pendingUpdate;
elasticClient.Update<dynamic>(updateRequest);

这导致请求:
{"update":{"_id":2,"_retry_on_conflict":3}}
{"doc":{}}

字段值未设置为null

在阅读此处 https://www.elastic.co/guide/en/elasticsearch/client/net-api/5.x/modifying-default-serializer.html之后,我尝试将序列化器修改为包含空值
var connectionSettings =
new ConnectionSettings(pool, connection, new SerializerFactory((settings, values) =>
{
settings.NullValueHandling = NullValueHandling.Include;
}));

现在我的要求变成:
{"update":{"_index":null,"_type":null,"_id":2,"_version":null,"_version_type":null,"_routing":null,"_parent":null,"_timestamp":null,"_ttl":null,"_retry_on_conflict":3}}
{"doc":{"DocumentType_TAG_PENDING_Id":null},"upsert":null,"doc_as_upsert":null,"script":null,"scripted_upsert":null}

我收到以下错误:
{"error":{"root_cause":[{"type":"json_parse_exception","reason":"Current token (VALUE_NULL) not of boolean type\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@181f5854; line: 1, column: 82]"}],"type":"json_parse_exception","reason":"Current token (VALUE_NULL) not of boolean type\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput@181f5854; line: 1, column: 82]"},"status":500}

请帮忙

最佳答案

到目前为止,我们有两种选择:

  • 升级到v6,他们在其中分离了文档并请求序列化程序。
    因此,我们可以自定义文档的序列化方式,而不会影响请求/响应头。有关更多信息,请参见https://www.elastic.co/guide/en/elasticsearch/client/net-api/master/custom-serialization.html
  • 在请求后使用 Elasticsearch 低级客户端,避免使用嵌套序列化程序。
    https://www.elastic.co/guide/en/elasticsearch/client/net-api/5.x/elasticsearch-net.html

  • 我们的首选方法是在一切正常的情况下进行升级,并在出现任何问题时恢复为低级客户端

    关于elasticsearch - 包含空值后, Elasticsearch 更新失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48929484/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com