c# - 如何使用嵌套客户端在 Elasticsearch 中按数组搜索数组属性

标签 c# elasticsearch nest

假设我们有一个名为 acls 的类,该类有一个名为 lprop 的 List 属性。

现在假设我有另一个值为 1、3、5 的列表,假设这个变量名称是 tosearch。

我想通过使用 nest 在 elasticsearch 的索引中搜索 acls 类型记录 lprop 属性中的值,并且只找到一个匹配项就足够了。

例如:

    `public class acls
    {
        public List<int> lprop {get;set;}
    }
    public void main()
    {
        //.. creating connection and etc..
        // we have 3 recs of acls
        // 1. lprop values: 2,4,6,8
        // 2. lprop values: 1,9,0,4
        // 3. lprop values: 6,7,8
        List<int> tosearch = new int[] { 1, 3, 5 }.ToList();
        //Now I want to search tosearch values in acls lprop values.
        // Result should be: 2. records
    }`

最佳答案

使用 Terms query

client.Search<acls>(s => s
    .Query(q => q
        .Terms(c => c
            .Field(p => p.lprop)
            .Terms<string>(tosearch)
        )
    )
);

关于c# - 如何使用嵌套客户端在 Elasticsearch 中按数组搜索数组属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36697563/

相关文章:

elasticsearch - 使用 NEST 在索引上设置 Elasticsearch 时间戳路径?

c# - Interlocked.CompareExchange(引用值,newValue,compareTo)

c# - QueryString containing\coming through with\\

elasticsearch - 如何查找特定EventId的最早和最新事件日期?

elasticsearch - 如何将 Azure 存储数据索引到弹性云

elasticsearch - 当使用短语时,elasticsearch查询字符串未执行预期的模糊查询

C# 部署项目 : Icon doesn't appear for the extension associated

c# - 同时调用或调用多个方法?

Elasticsearch 使用 jest 通过查询删除

elasticsearch - 如何将嵌套类型与 NEST 客户端一起用于 Elastic Search