我正在尝试使用NEST将文档批量索引到Elasticsearch索引,而不指定要编制索引的文档的类类型。我以前使用不同的流程创建了索引及其映射。
我用来尝试索引的电话是:
var descriptor = new BulkDescriptor();
foreach (var item in itemsToIndex)
{
descriptor.Index<string>(bd => bd
.Document(item.Message)
.Routing(item.Routing)
.Type(item.MessageType)
.Index(indexName));
}
索引进程可以访问Document,Routing,Type和index,但不能访问文档类。这是因为正在从与索引创建和映射逻辑分开的队列中读取文档。
在上面的代码示例中,item是SQS消息的包装器,用于公开该消息体和属性。
在上面的代码中,我只是使用&lt;串取代。我也试过&lt;对象&gt;但在这两种情况下都会出错。批量描述符的内容如下所示:
Nest.IBulkIndexOperation<object>.Document = {"invoiceId":"f545387b-cbd4-4dd7-8511-39a10632c506","enteredByUserID":.................,"updatedDateUTC":"2016-11-22T17:21:55.227","createdDateUTC":"2016-11-22T17:21:55.077"}
索引请求的调试信息响应是:
Invalid NEST response built from a successful low level call on POST: /_bulk
# Invalid Bulk items:
operation[0]: index returned 400 _index: index_1 _type: Invoice _id: 3df6bc600278be4c3ff3836d25c2479c _version: 0 error: Type: mapper_parsing_exception Reason: "failed to parse" CausedBy:
Type: not_x_content_exception Reason: "Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"
# Audit trail of this API call:
- [1] HealthyResponse: Node: http://127.0.0.1:9200/ Took: 00:00:02.3129982
# Request:
{"index":{"_index":"search_1","_type":"Invoice","_id":"3df6bc600278be4c3ff3836d25c2479c","_routing":"5337bab8-..."}}
"{\"invoiceId\":\"f545387b-cbd4-4dd7-8511-39a10632c506\",\"enteredByUserID\":\"71259d....."updatedDateUTC\":\"2016-11-22T17:21:55.227\",\"createdDateUTC\":\"2016-11-22T17:21:55.077\"}"
# Response:
{"took":375,"errors":true,"items":[{"index":{"_index":"index_1","_type":"Invoice","_id":"3df6bc600278be4c3ff3836d25c2479c","status":400,"error":{"type":"mapper_parsing_exception","reason":"failed to parse","caused_by":{"type":"not_x_content_exception","reason":"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"}}}}]}
任何想法是否有可能做我正在尝试做的事情,或者如果有一个解决方法我错过了?注意:我用....替换了一些索引文档。
答案 0 :(得分:0)
看起来我使用的是错误的客户端。当我使用ElasticLowLevelClient时,我让它工作。
BulkDescriptor定义是ElasticClient客户端的一部分,它不处理低级(原始)请求。