我正在使用Nest Client与ElasticSearch进行通信。
当我尝试索引子类型时,它会在标题中给出错误。我已经在父类型上设置了这个属性:[ElasticType(Name =" item",IdProperty =" id")]。这应该告诉id字段的弹性类型。
以下是带有错误信息的nest进行的查询。
{StatusCode: 400,
Method: PUT,
Url: http://localhost:9200/itemindex/inventory/15894?routing=15894&parent=15894,
Request: {
"itemId": 15894,
"inventories": [
{
"storeId": 20693,
"inventoryCount": 40
}
]
}
Response: {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Can't specify parent if no parent field has been configured"}],"type":"illegal_argument_exception","reason":"Can't specify parent if no parent field has been configured"},"status":400}}
当我直接使用此查询时感觉。它成功插入和更新数据。但是,当我尝试使用Nest时,不是这样。
请建议?任何帮助表示赞赏。提前谢谢。
有人可以解释这个错误的原因吗?
答案 0 :(得分:1)
我不知道您的索引映射,但看起来您在定义子文档的映射时忘记指定parent。
这是使用NEST 2.0.0-alpha1执行此操作的方法。
public class Parent
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Child
{
public int Id { get; set; }
public string Name { get; set; }
}
var response = client.CreateIndex(indexName, d => d
.Mappings(map => map
.Map<Parent>(m => m.AutoMap())
.Map<Child>(m => m.AutoMap().Parent<Parent>())));
希望它有所帮助。