Multi Terms search NEST C#

Orelus picture Orelus · Oct 6, 2013 · Viewed 8.2k times · Source

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.

Answer

Martijn Laarman picture Martijn Laarman · Oct 14, 2013

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.