elasticsearch get documents total count in index using php API

Oto Shavadze

I have created elasticsearch index:

$es = Elasticsearch\ClientBuilder::create()->build();

$params = [
    'index'=>'articles',
    'type'  => 'article'
];

for ($i=0; $i<30; $i++) {
    $params['body'] = [ 'title'=>'title '.$i, 'body'=>'text '.$i ];
    $response = $es->index($params);
}

So, 30 documents are added, now I need get total count of records. This works

$search_params= [
    'index'=>'articles',
    'type'  => 'article',
];

$query = $es->search($search_params);

echo $query['hith']['total'];

But as I've read, more efficient is using straight counting _count method.

My problem is, that I not understood how to implement _count in php API?

tried:

$search_params= [
    'index'=>'articles',
    'type'  => 'article',
    'body' => [ 
        'query'  => ['_count'=>[] ] 
    ]
];

$query = $es->search($search_params);

and several another variants, but don't get right one syntax.

Help?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Get a count of total documents with MongoDB when using limit

Get all documents from an index using spring-data-elasticsearch

Elasticsearch - Java RestHighLevelClient - how to get all documents using scroll api

Not able to get count of documents from cosmos using powershell rest API

Get all documents from an index - elasticsearch

How to get the total number of documents stored inside MongoDB collection using PHP

eBay API to get Total Amount using GetOrders by PHP

Getting count of total documents when using aggregation along with skip and limit

Elasticsearch Java API - How to get the number of documents without retrieving the documents

How to get the total count of documnets present in an index using JAVA High Level Rest Client

Get count of documents missing a field over a date histogram in ElasticSearch?

Get total count using a window function

deleting all documents with out dropping index in elasticsearch java API

how to return the count of unique documents by using elasticsearch aggregation

How to get total result count when setFrom is used in elasticsearch QueryBuilders?

How to get total watchers count in elasticsearch v 8,x,x

How can I get total count of each words in elasticsearch document?

Get user total starred count using Github API v3

Get total count of matching documents and count within that subset that satisfies certain criteria

want to get total count of records in a table using COUNT(*) in MySQL

Count number of documents in an ElasticSearch snapshot

FireStore Swift 4 : How to get total count of all the documents inside a collection, and get details of each document?

How to get get unique and total count from Mongodb sub-documents for each main doc

Elasticsearch python api GET index stats

Get all data from index elasticsearch in php

Updating existing documents in ElasticSearch (ES) while using rollover API

Retrieve documents from Completion Suggester using Elasticsearch Java API

Get total number of documents in mongodb

How to get total documents in mongoose?

TOP Ranking

HotTag

Archive