Reputation: 741
I'm trying to bulk index documents to an Elasticsearch index using NEST without specifying the class type of the document being indexed. I've previously created the index and it's mappings using a different process.
The call I'm using to try and index is:
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));
}
The indexing process has access to the Document, Routing, Type and index, but not the document class. This is because the documents are being read from a queue that is separate from the index creation and mapping logic.
In the code sample above the item is a wrapper for a SQS Message that exposes that message body and attributes.
In the code above I'm just using < string>. I also tried it with < object> but get an error in both situations. The contents of the bulk descriptor looks like:
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"}
And the debuginformation response from the index request is:
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"}}}}]}
Any idea if it's possible to do what I'm trying to do, or if there's a work around I'm missing? Note: I replaced some of the index document with ....
Upvotes: 1
Views: 830
Reputation: 741
Looks like I was using the wrong client. I got it to work when I used ElasticLowLevelClient.
The BulkDescriptor definition is part of the ElasticClient client which doesn't handle low level (raw) requests.
Upvotes: 1