社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Elasticsearch

在ElasticSearch中对嵌套集合执行查询,嵌套在.NET Core中

Xelit3 • 5 年前 • 656 次点击  

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

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

}

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

我现在拥有的是:

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

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

有什么想法吗?

提前谢谢大家

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43584
 
656 次点击  
文章 [ 1 ]  |  最新文章 5 年前
Russ Cam
Reply   •   1 楼
Russ Cam    6 年前

你不需要表演 nested 查询以查询 Tags 字段,因为每个标记只是一个原始json值,即 string . 只是 terms 查询就足够了。

在哪里 嵌套的 需要查询的是 标签 是具有多个属性的poco,映射为 嵌套的 数据类型。