Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the total number of documents found using the Nest?

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?

like image 536
helvar Avatar asked Sep 25 '14 14:09

helvar


People also ask

How to count the total number of documents in a collection?

On the other hand, when it comes to Firestore, t he massively scalable NoSQL database from Google, you won’t find a built-in API that can help you count the total number of documents in a collection. So by default, you’ll have to download all documents within the collection and count them one by one on the client.

How do I Count the number of documents in a model?

Model.count ( {}, function (err, count) { console.log ( "Number of docs: ", count ); }); Model.find ().count (function (err, count) { console.log ("Number of docs: ", count ); }); using count is deprecated and you can also use "Collection.countDocuments" or "Collection.estimatedDocumentCount" exactly the way you used "count".

How to count the number of documents in a mongoose model?

You can use the mongoose-auto-increment plugin for this. If you are using node.js >= 8.0 and Mongoose >= 4.0 you should use await. const number = await Model.countDocuments (); console.log (number); If anyone's checkin this out in 2019, count is deprecated. Instead, use countDocuments.

How do I Count the number of files in a folder?

Sync / add a shortcut to File Explorer. Then use file explore to right click, and see the count of all folders and files in the hierarchy. Kind of a pretty big oversight that you can't do this in SharePoint. You can only go to doc settings and see a full file count, but not a folder count.


2 Answers

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.

like image 95
Greg Marzouka Avatar answered Sep 27 '22 20:09

Greg Marzouka


The best way is to use the method Count as proposed by the official documentation

here the code

var result = client.Count<ElasticsearchProject>();
like image 41
Angelo Nodari Avatar answered Sep 27 '22 21:09

Angelo Nodari