Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
    }`
like image 450
zokkan Avatar asked Apr 18 '16 14:04

zokkan


Video Answer


1 Answers

Use a Terms query

client.Search<acls>(s => s
    .Query(q => q
        .Terms(c => c
            .Field(p => p.lprop)
            .Terms<string>(tosearch)
        )
    )
);
like image 128
Russ Cam Avatar answered Sep 19 '22 10:09

Russ Cam