我试图插入具有嵌套数据类型的整个数据,但是低级客户端(C#)无法插入。
最新的Elasticsearch文档没有说明我们如何做到这一点。
所以,我不确定我需要做什么。有人可以帮我吗?
VendorProduct被创建为嵌套类型。
对应:
"properties": {
"vendorProducts": {
"properties": {
...
},
"type": "nested"
},
}
批量API上的批量插入请求;
{"index":{"_index":"productindextemp-local82","_type":"elasticproduct","_id":"1715"}}
{
"id": 1715,
"productTypeId": 5,
...
"vendorProducts": [
{
"id": 124550,
"productId": 1715,
"vendorId": 8,
..
},
{
"id": 451542,
"productId": 1715,
"vendorId": 15,
..
}
]
}
服务器:
AWS Elastic Search Service v7.1
C#引用:
Elasticsearch.Net v7.4.1
Nest v7.4.1
我们的C#辅助代码为;
var settings = new ConnectionSettings(new System.Uri(ElasticUrl));
settings.DefaultMappingFor<ElasticProduct>(d => d.IndexName(newTempIndexName));
settings.RequestTimeout(TimeSpan.FromHours(5));
var client = new ElasticClient(settings);
if (!client.Indices.Exists(newTempIndexName).Exists)
{
client.Indices.Create(
newTempIndexName,
c => c.Map<ElasticProduct>(m => m
.AutoMap()
.Properties(p => p
.Nested<List<ElasticVendorProduct>>(n => n
.Name(nn => nn.VendorProducts)
.AutoMap()
)
)
)
);
}
StringBuilder stringBuilder = new StringBuilder();
foreach (var data in productBulkDataItems)
stringBuilder.Append(data).Append("\n");
var result = client.LowLevel.Bulk<BulkResponse>(newTempIndexName, stringBuilder.ToString());
发送请求后,我们已收到此错误。因此,结果为空。我无法处理这个问题。我们从.net上的Nest客户端提取了Json请求,然后尝试在kibana上手动发送请求。这种方法也给我们同样的结果。
异常(exception):
{index returned 400 _index: productindextemp-local82 _type: elasticproduct _id: 1715 _version: 0 error: Type: illegal_argument_exception Reason: "object mapping [vendorProducts] can't be changed from nested to non-nested"}
最佳答案
尝试创建索引时,必须将索引名称从“ elasticproduct ”更改为“ _doc ”。您的输出数据应如下所示:
"mappings": {
"_doc": {
"properties": {
...
}
}
}
尝试使用
"_type":"_doc"
而不是"_type":"elasticproduct"
。
关于c# - 如何使用Elastic low-level-client批量插入嵌套类型对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58976244/