Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi Terms search NEST C#

I want to do a search matching multiple values ( an array of values ) like this :

var result1 = _client.Search<type1>(s => s
            .Fields(f => f.trip_id)
            .Query(q => q
                .Terms(t => t.arg1, value1)).Take(_allData))
                .Documents.Select(d => d.arg2).ToArray();

var result2 = _client.Search<type2>(s => s
                      .Query(q => q
                          .Terms(t => t.arg3, result1))
                          .Take(_allData)
                          ).Documents.Select(s => s.ar3).ToList();

How can I do ? I was thinking about facets but I don't see how I can do it. The only way for now that works is with a foreach iterator which is not really effective...

Thanks for your help.

like image 819
Orelus Avatar asked Oct 06 '13 20:10

Orelus


1 Answers

You can express multiple queries like so:

.Query(q=>q.Terms(t=>t.arg3, result1) && q.Terms(t=>t.arg1, value1))

Be sure to read the documentation on writing queries to discover all the good stuff NEST has to offer.

like image 141
Martijn Laarman Avatar answered Oct 03 '22 11:10

Martijn Laarman