Include_In_Parent option for ElasticSearch and NES

2019-09-07 04:40发布

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条回答
beautiful°
2楼-- · 2019-09-07 05:15

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())
查看更多
登录 后发表回答