【发布时间】:2019-11-21 13:31:16
【问题描述】:
我试图插入具有嵌套数据类型的整个数据,但低级客户端(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 弹性搜索服务 v7.1
c# 参考: Elasticsearch.Net v7.4.1 巢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 上手动发送请求。这种方法也给了我们同样的结果。
例外:
{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"}
【问题讨论】:
-
请您编辑您的问题以显示您正在做什么以获得您看到的异常
-
什么是
productBulkDataItems?ElasticProduct和ElasticVendorProduct的定义是什么?
标签: c# elasticsearch nested nest bulk