File tree Expand file tree Collapse file tree 1 file changed +26
-5
lines changed Expand file tree Collapse file tree 1 file changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -308,14 +308,35 @@ private function executeSearch(Search $search): array
308308
309309 public function getIndexDocumentCount (): int
310310 {
311- $ body = [
312- 'index ' => $ this ->getIndexName (),
313- 'body ' => [],
314- ];
311+ return $ this ->count ();
312+ }
313+
314+ /**
315+ * Counts documents by given search.
316+ *
317+ * @param Search|null $search
318+ * @param array $params
319+ * @param bool $returnRaw If set true returns raw response gotten from client.
320+ *
321+ * @return int|array
322+ */
323+ public function count (Search $ search = null , array $ params = [], $ returnRaw = false )
324+ {
325+ $ body = array_merge (
326+ [
327+ 'index ' => $ this ->getIndexName (),
328+ 'body ' => $ search !== null ? $ search ->toArray () : [],
329+ ],
330+ $ params
331+ );
315332
316333 $ results = $ this ->getClient ()->count ($ body );
317334
318- return $ results ['count ' ];
335+ if ($ returnRaw ) {
336+ return $ results ;
337+ } else {
338+ return $ results ['count ' ];
339+ }
319340 }
320341
321342 public function remove ($ id , $ routing = null )
You can’t perform that action at this time.
0 commit comments