提问人:clayon_jo 提问时间:9/4/2023 更新时间:9/4/2023 访问量:29
使用 NEST 为同一文档批量添加嵌套对象
Bulk add nested object for the same document with NEST
问:
我在 Elastic Search 中有一个带有此映射的索引:
{
"properties": {
"allSubjects": {
"type": "nested",
"properties": {
"nuis": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256.0,
"type": "keyword"
}
}
},
"dateOfInspection": {
"type": "date"
}
}
},
"iD": {
"type": "keyword"
}
}
}
嵌套对象将有超过 300K 行。但是当我尝试添加它时,会出现以下错误:
Invalid NEST response built from a unsuccessful (413) low level call on PUT:
我曾想过这样做。我想用 10K 将 300K 对象分成更小的批次,然后为同一个文档逐个添加。但是当我尝试这样做时,它只保存了最后一批,因此它覆盖了它们。 我尝试为第一批创建文档,然后使用以下命令更新文档:
public bool AddToElasticObjectsBulk(SobElastic sobElastic)
{
var chunks = sobElastic.AllObjects.Chunk(10000);
if (chunks.Count() > 1)
{
var indexResponse = _elasticClient.Index(new SobElastic()
{
ID = sobElastic.ID,
AllObjects = chunks.ElementAt(0).ToList()
}, d => d.Index("my-obj"));
}
var leftChunks = chunks.Skip(1);
for (int i = 0; i < leftChunks.Count(); i++)
{
var sobElastic1 = new SobElastic()
{
ID = sobElastic.ID,
AllObjects = leftChunks.ElementAt(i).ToList()
};
var bulkResponse = _elasticClient.IndexDocument(sobElastic);// this is wrong i know but here is where i need help
}
return true;
}
答: 暂无答案
评论