It would be nice to have a number of items without having to search, for example
Obj.search("id:*").count
Is it possible?
First you must use the match_all query: MyModel.search( { query { all } }).results.total . (In Lucene, avoid oncoming requests at all costs.)
match_all
MyModel.search( { query { all } }).results.total
Tire does not currently provide a "count" API. That will change.
In ElasticSearch, you can count all the elements using the account API
curl -XGET http://localhost:9200/index/_count
See the Count API on your website.
Just got a hint from Karmi. The counting API is now available.
You can do the following:
s = Tire.search 'articles-test', :search_type => 'count' do query { term :tags, 'ruby' } end
Defined only then s.results.total .
s.results.total
See here: https://github.com/karmi/tire/blob/master/test/integration/count_test.rb
You can do this in elasticsearch-model stone:
elasticsearch-model
Article.search("cats", search_type: 'count').results.total # => 2026
And you will not call a selection ...
Article.search("cats", search_type: 'count').map {|r| r.title} # => []
If you are using gem 'elasticsearch-model', here is a good liner:
Elasticsearch::Model.client.count(index: 'your_index_name_here')['count']
If you want to get the number of documents inside the index, you can also just check the index statistics , for example:
curl -XGET localhost:9200/_stats
As a result, you will receive the number of documents / deleted documents (documents have not yet been combined).
From the console:
Model.search("*:*").results.total
can help someone;)
Source: https://habr.com/ru/post/900538/More articles:Python will not read sys.argv - pythonMicrosoft SQL Server Management Studio runs a script from within a script - sqlMips how to save user input string - stringGet line numbers from .NET exceptions without .pdb files - c #Saving utf-8 data with Doctrine2 in Symfony2 - mysqlPython foreach back - pythonphp behavior when post_max_size is exceeded - javamaxRequestLength - details are needed behind the scenes! - asp.netEclipseLink and log4j: how to use both - javaAdd Guava to new Maven IntelliJ module - javaAll Articles