【发布时间】:2014-05-21 15:51:48
【问题描述】:
我一直致力于将我的 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 时,它会自动添加一个路由属性,并将“必需”设置为“真”。在 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 带有 JSON 错误消息的错误请求:
error=RoutingMissingException[[test_index]/[stocks]/[xx]] 需要路由
(其中 xx 是文档的 ID)
我假设我必须在某处插入一个路由字符串,但我不知道在哪里。我尝试在 BulkParameters 中添加一个“路由”参数,但这根本不起作用。谁能给点建议?
【问题讨论】:
标签: c# elasticsearch nest