In ElasticSearch(Nest), Can't specify parent if no parent field has been configured

匿名 (未验证) 提交于 2019-12-03 01:05:01

问题:

I am using Nest Client to communicate with ElasticSearch.

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}} 

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?

回答1:

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

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>())));    

Hope it helps.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!