【问题标题】:Perform a query over a nested collection in ElasticSearch with NEST in .NET Core使用 .NET Core 中的 NEST 对 ElasticSearch 中的嵌套集合执行查询
【发布时间】:2019-07-20 14:52:35
【问题描述】:

我正在尝试对以下对象的索引执行搜索:

public class IndexedElement
{

    public Guid Id { get; set; }
    public long RowId { get; set; }
    public IndexedElementType Type { get; set; }
    public string Summary { get; set; }
    public string Description { get; set; }

    public IList<string> Tags { get; set; }

}

目的是通过摘要属性进行搜索,或者通过匹配标签集合中的任何字符串

我目前拥有的是这样的:

    public IEnumerable<IndexedElement> Search(string description)
    {
        var query = GetClient().Search<IndexedElement>(s => s.From(0).Size(5)
            .Query(
                q => q.Term(p => p.Summary, description)
                ||
                q.Nested(n => n.Path(p => p.Tags).Query(q2 => q2.Terms(t => t.Field(f => f.Tags).Terms(description))))                    
            ));

        return query.Documents.ToList();
    }

但是嵌套部分不起作用,我不知道我是否以正确的方式使用它,或者我必须为此找到另一个解决方案。

有什么想法吗?

提前谢谢大家

【问题讨论】:

    标签: c# elasticsearch asp.net-core .net-core nest


    【解决方案1】:

    您无需执行nested 查询即可查询Tags 字段,因为每个标签只是一个原始JSON 值,即string。只需 terms 查询就足够了。

    需要nested 查询的地方是Tags 是具有多个属性的POCO,并被映射为nested 数据类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-27
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 2022-06-10
      • 1970-01-01
      相关资源
      最近更新 更多