我一直致力于将我的ElasticSearch(ES)0.9代码转换为与ES 1.0一起使用。这需要将NEST升级到最新的预发布版本。
我一直在尝试批量索引一组子文档。我已将其映射设置为:
"stocks": {
"_parent": {
"type": "products"
},
"_timestamp": {
"enabled": true
},
"properties": {
"id": {
"type": "integer",
"index": "not_analyzed"
},
"stock": {
"type": "integer",
"index": "not_analyzed"
}
}
}
这是在ES 0.9中创建的。当我将它放入ES 1.0时,它会自动添加一个路由属性,其中包含'必需'设为' true'。在Google上进行的搜索表明,启用父子文档设置始终需要这样做,但是当我检查0.9分片中的文档时,该属性从未明确显示。
"好的..."我想对自己。接下来,我有NEST的以下代码块:
var bulkParams = postQueue.Select(p => new BulkParameters<Stock>(p) { Parent = p.id.ToString()});
IElasticsearchResponse c = ec.IndexMany(bulkParams, null, "stocks").ConnectionStatus;
返回NullReferenceException。经过一番猜测后,我将Id参数添加到BulkParameters中:
var bulkParams = postQueue.Select(p => new BulkParameters<Stock>(p) { Id = p.id.ToString(), Parent = p.id.ToString()});
这似乎有效,但请求会从ES返回错误响应:
400 Bad Request with JSON错误消息:
错误= RoutingMissingException [[test_index] / [个股] / [xx]需要路由]
(其中xx是文档的id)
我假设我必须在某处插入路由字符串,但我不知道在哪里。我尝试过添加&#39;路由&#39;参数进入BulkParameters,但根本不起作用。任何人都可以建议吗?
答案 0 :(得分:3)
已IndexMany()
BulkParameters
NEST 1.0.0 beta 1
对Bulk()
的支持
如果要使用具有更高级参数的批量,则现在必须使用BulkParameters
命令。
该版本仍然附带"bulkparameters``1``"
类in the assembly
此后已在开发分支中删除,并将在下一次测试版更新中发布。
现在发生的情况是,您实际上是使用适当的单个批量元数据集索引"stock"
类型文档而不是Bulk()
。
在为各个项目配置高级参数时,请参阅here for an example,了解如何使用{{1}}一次索引多个对象。