How to search array property by array in elasticsearch with nest client

Deadly 提交于 2019-12-07 07:11:45

问题


Lets say we have a class called acls and this class has a List property called lprop.

Now lets say I have another List which has values 1,3,5 and lets say this variables name is tosearch.

I want to search tosearch values in acls typed records lprop property in an index of elasticsearch by using nest and finding only one match is sufficient.

Ex:

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

回答1:


Use a Terms query

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


来源:https://stackoverflow.com/questions/36697563/how-to-search-array-property-by-array-in-elasticsearch-with-nest-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!