Include_In_Parent option for ElasticSearch and NEST library

喜夏-厌秋 提交于 2019-12-13 03:44:31

问题


I am using ElasticSearch and the NEST .Net library for implementing the Search functionality needed in our app. In my model, I have a type that contains Nested objects as per below.

[ElasticType(Name = "x")]
public class X
{
    [ElasticProperty(IncludeInAll = false, Index = FieldIndexOption.NotAnalyzed)]
    public string Id { get; set; }  

    [ElasticProperty(Type = FieldType.Nested)]
    public List<Y> Ys { get; set; }   
}

Any queries executed against X are actually executed against the List of Ys. I would like to highlight the hits in the nested objects and based on https://github.com/elasticsearch/elasticsearch/issues/5245 .

However, in order to use the proposed workaround, the include_in_parent option should be true for the nested object.

How can this option be enabled using the NEST library? Is there any ElasticProperty property (I haven’t found any obvious one) or some other way to do so?

Thank you


回答1:


Apparently this can be done only by using fluent syntax. For the above case the code would be:

.AddMapping<X>(m => m
    .Properties(p => p
         .NestedObject<Y>(n => n
             .Name("ys")
             .IncludeInParent())


来源:https://stackoverflow.com/questions/27502678/include-in-parent-option-for-elasticsearch-and-nest-library

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