Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to count all elements of an index in ElasticSearch or Tire?

It would be nice to have a count of elements without having to do a search like

Obj.search("id:*").count

Is this possible?

like image 948
Jeremy Smith Avatar asked Nov 01 '11 16:11

Jeremy Smith


People also ask

What is index rate in Elasticsearch?

2. How is an index rate used in Elasticsearch? Elasticsearch is a powerful open source search and analytics engine that makes data easy to explore. An index rate is used in Elasticsearch to keep track of how often a document is updated.

What is Elasticsearch index size?

all_fields_idx index, which contains all the fields, has a primary storage size of 8.6kb.

What are hits in Elasticsearch?

A search consists of one or more queries that are combined and sent to Elasticsearch. Documents that match a search's queries are returned in the hits, or search results, of the response.


2 Answers

In ElasticSearch you can count all elements using the count API

curl -XGET http://localhost:9200/index/_count

See the Count API docs on their site.

like image 123
David Kullmann Avatar answered Oct 19 '22 02:10

David Kullmann


First, you should use the match_all query: MyModel.search( { query { all } }).results.total. (In Lucene, avoid wildcard queries at all costs.)

Presently, Tire does not expose the "count" API. That will change.

like image 9
karmi Avatar answered Oct 19 '22 02:10

karmi