6

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

1 Answer 1

9

Use a Terms query

client.Search<acls>(s => s
    .Query(q => q
        .Terms(c => c
            .Field(p => p.lprop)
            .Terms<string>(tosearch)
        )
    )
);
Sign up to request clarification or add additional context in comments.

6 Comments

tosearch variable is List<int> which contains values to match, will 1 query sufficient or should I generate more terms queries and OR them?
terms query does an OR on the passed terms i.e. a document field only needs to match one term to be considered a match. The documentation has more details - elastic.co/guide/en/elasticsearch/reference/2.3/…
could I use int instead of List<int> for tosearch value?
Terms can take an IEnumerable<T> or a params T[] so you can pass n number of T to .Terms()
@gmd no, if you have a List<int>, then use .Terms<int>(IEnumerable<int> terms)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.