如何将字节数组另存为NEST中的数组

时间:2018-09-16 11:26:33

标签: c# arrays .net elasticsearch nest

我有一个具有以下定义的简单POCO对象

class MyClass 
{
   public byte[] Assortment {get;set;}
}

我想在Elasticsearch中将其另存为[1,2,3]。但是,当我简单地创建该类型的对象并将其插入索引时,我只是得到一些二进制编码值。示例代码:

var settings = new ConnectionSettings(new Uri(elasticSettings.NodeUri)).DefaultIndex(elasticSettings.Index);
var elasticClient = new ElasticClient(settings);
MyClass[] requests = { new MyClass {Assortment = new byte[] {1,3,40,2,9,4,7,5,8,47,45,46,38,39,6} }};
var bulkResponse = await elasticClient.IndexManyAsync(requests, cancellationToken: cancellationToken);

如果我手动创建索引并设置数组类型,则保存时会出现以下错误:

System.AggregateException: One or more errors occurred. (Error while processing bulk request: Invalid NEST response built from a successful low level call on POST: /_bulk
# Invalid Bulk items:
  operation[0]: index returned 400 _index: blockchain _type: elasticrequest _id: eqa04WUByNd1edqilegT _version: 0 error: Type: mapper_parsing_exception Reason: "failed to parse [assortment]" CausedBy:
Type: illegal_argument_exception Reason: "For input string: "AQMoAgkEBwUILy0uJicG""
  operation[1]: index returned 400 _index: blockchain _type: elasticrequest _id: e6a04WUByNd1edqilegT _version: 0 error: Type: mapper_parsing_exception Reason: "failed to parse [assortment]" CausedBy:
Type: illegal_argument_exception Reason: "For input string: "AQMoAgkEBwUILy0uJicG""
  operation[2]: index returned 400 _index: blockchain _type: elasticrequest _id: fKa04WUByNd1edqilegT _version: 0 error: Type: mapper_parsing_exception Reason: "failed to parse [assortment]" CausedBy:
Type: illegal_argument_exception Reason: "For input string: "AQMoAgkEBwUILy0uJicG""

我不想对值进行二进制编码,我只想创建一个值数组。

我尝试使用文本/数字/对象属性,但是它们不起作用。

0 个答案:

没有答案