如何使用Elastic低级别客户端对嵌套类型对象进行大容量插入



我试图用嵌套的数据类型插入整个数据,但低级客户端(c#(无法插入。

最新的弹性搜索文档并没有解释我们如何做到这一点。

所以,我不确定我需要做什么。有人能帮我吗?

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.1Nest 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());

我们在发送请求后收到此错误。因此,结果为null。我无法处理这个问题。我们已经在.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"}

当您尝试创建索引时,必须将索引名称从">elasticproduct"更改为">_doc"。您的输出数据应该是这样的:

"mappings": {
"_doc": {
"properties": {
...
}
}
}

尝试"_type":"_doc"而不是"_type":"elasticproduct"

最新更新