如何使用nest client在elasticsearch中按数组搜索数组属性

zok*_*kan 4 c# elasticsearch nest

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

现在假设我有另一个列表,其值为1,3,5,并且假设此变量名称为tosearch.

我想通过使用nest搜索弹性搜索索引中的acls类型记录lprop属性中的tosearch值,并且只查找一个匹配就足够了.

例如:

    `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
    }`
Run Code Online (Sandbox Code Playgroud)

Rus*_*Cam 5

使用Terms查询

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