在ElasticSearch(Nest)中,如果未配置父字段,则无法指定父 [英] In ElasticSearch(Nest), Can't specify parent if no parent field has been configured

查看:768
本文介绍了在ElasticSearch(Nest)中,如果未配置父字段,则无法指定父的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Nest Client to communicate with ElasticSearch.

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

When i trying to index child type it is giving me error in the heading. I have already set this attribute on Parent Type : [ElasticType(Name ="item", IdProperty = "id")]. This should tell elastic type about id field.

下面是嵌套错误信息的查询.

Below is the query made by nest with error info.

{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时却没有.

When i am using this query directly with sense. It is successfully inserting and updating data. But not when i try with Nest.

请提出建议?任何帮助表示赞赏.预先谢谢你.

Please suggest? Any help is appreciated. Thank you in advance.

任何人都可以解释此错误的原因吗?

Could any one explain the reason of this error?

推荐答案

我不知道您的索引映射,但似乎您在为子文档定义映射时忘记指定父级.

I don't know your index mapping, but looks like you forgot to specify parent when defining mapping for child document.

这是使用NEST 2.0.0-alpha1进行此操作的方式.

This is how you can do this with 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(Nest)中,如果未配置父字段,则无法指定父的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆