Reputation: 133
I do the same request using the nest, and directly in ElastichSearch. When I see direct request, how many documents match request.
"hits":
{
"total": 1640,
"max_score": 1,
"hits": [...]
}
My query:
var search = client.Search<RCompany>(s => s.Index("MyIndex")
.Query(qq => qq
.Filtered(m => m.Filter(f => f.Bool(b => b
.Must(
a => a.Term(z => z.Company.Code, param1),
a => a.Terms(z => z.Company.Id, param2),
a => a.Terms(z => z.Company.Field1.Id, param3)
)))
.Query(b => b.Bool(q => q.Should
(n => n.Match(a => a.OnField(d => d.Company.Field2).Query(param5).Operator(Operator.And)),
n => n.Match(a => a.OnField(d => d.Company.Field3).Query(param5).Operator(Operator.And)),
n => n.Match(a => a.OnField(d => d.Company.Field4).Query(param5).Operator(Operator.And)),
n => n.Match(a => a.OnField(d => d.Company.Field5).Query(param5).Operator(Operator.And))
)))))
.Size(10)
.SortDescending(n => n.DtCreate));
How can I find out how many documents suitable request using Nest?
Upvotes: 6
Views: 6297
Reputation: 385
The best way is to use the method Count as proposed by the official documentation
here the code
var result = client.Count<ElasticsearchProject>();
Upvotes: 4
Reputation: 3325
There is a Total
property on ISearchResponse
which holds the total number of documents that matched the query. In your example, that would be search.Total
.
Upvotes: 12