Reputation: 751
I have a big query in NEST that is constructed from 2 query containers. Now i would like to limit the size of the returned documents of one query container to 10 and no limit to the other query container. For my result i need to have .Take(take) and .Skip(skip) for pagination. This is an example:
var result = EsClient.Search<Business>(q => q
.Query(qq =>
{
QueryContainer nearByQuery= null;
QueryContainer locationQuery = null;
locationQuery = qq.Term("postCode", toLowSearchLocation);
nearByQuery = qq
.Filtered(ft => ft
.Filter(fl => fl
.Bool(n => n
.MustNot(x => x.Term(na => na.PostCode, searchLocation.ToLower()))
)
);
return locationQuery || nearByQuery;
Now what i really want is to put a .Size on the second query so i get only 10 from that one. Did anybody know how ?
Thanks!
Upvotes: 1
Views: 1865
Reputation: 3325
Not possible with the Search endpoint as it only takes a single query. Even though you are building two separate queries in code, once you OR them together, they become one.
The best way to achieve this would probably be to use multi search, which will allow you to execute multiple queries in a single request, in which you could specify the desired size for each.
NEST example:
var result = EsClient.MultiSearch<Business>(ms => ms
.Search<Business>(s => s.Size(50).Query(locationQuery))
.Search<Business>(s => s.Size(10).Query(nearByQuery))
);
See these tests for more examples.
Upvotes: 2