gpt4 book ai didi

elasticsearch - 在ElasticSearch(Nest)中,如果未配置父字段,则无法指定父

转载 作者:行者123 更新时间:2023-12-02 22:31:51 24 4
gpt4 key购买 nike

我正在使用Nest Client与ElasticSearch通信。

当我尝试索引子类型时,标题出现错误。我已经在“父类型”上设置了此属性:[ElasticType(Name =“item”,IdProperty =“id”)]。这应该告诉有关id字段的 flex 类型。

以下是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时却没有。

请提出建议?任何帮助表示赞赏。先感谢您。

谁能解释这个错误的原因?

最佳答案

我不知道您的索引映射,但是看起来您在为子文档定义映射时忘记指定父级。

这就是使用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>())));

希望能帮助到你。

关于elasticsearch - 在ElasticSearch(Nest)中,如果未配置父字段,则无法指定父,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34849783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com