本文介绍了ElasticSearch和NEST库的Include_In_Parent选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ElasticSearch和NEST .Net库来实现我们应用程序所需的搜索功能。在我的模型中,我有一个包含嵌套对象的类型,如下所示。

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

对X执行的任何查询实际上是针对Y列表执行的。我想突出显示嵌套对象中的匹配,并基于。

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 .

但是,为了使用提出的解决方法,嵌套对象的include_in_parent选项应该为true。

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

如何使用NEST库启用此选项?有没有ElasticProperty属性(我没有找到任何明显的)或其他方式这样做?

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?

谢谢

推荐答案

显然这只能用流畅的语法来完成。对于上述情况,代码将是:

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

这篇关于ElasticSearch和NEST库的Include_In_Parent选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 22:44