【问题标题】:Include_In_Parent option for ElasticSearch and NEST libraryElasticSearch 和 NEST 库的 Include_In_Parent 选项
【发布时间】:2015-01-05 16:03:53
【问题描述】:

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

[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 列表执行的。我想突出嵌套对象中的命中并基于https://github.com/elasticsearch/elasticsearch/issues/5245

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

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

谢谢

【问题讨论】:

    标签: elasticsearch nest


    【解决方案1】:

    显然,这只能通过使用流利的语法来完成。对于上述情况,代码为:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-12-22
      • 1970-01-01
      • 2015-04-03
      • 2015-06-27
      • 1970-01-01
      • 1970-01-01
      • 2022-09-24
      相关资源
      最近更新 更多