I'm doing a bulk operation to index 100 documents at once using the python ElasticSearch Client. I want to count the total number of documents in an index. So I do the bulk op and then count the number of documents in an index as below:
helpers.bulk(es_client, actions);
es_client.count('index').get('count')
However the second line still returns the old count, and I tried to run the second line from a different file, which returns the correct result. I suspect that bulk op is not yet completed. Please correct me if I'm wrong, and what would be the workaround to do what I want?
The doc count is summed up among all shards, including replicas. Since you have one replica per primary shard, this can inflate the doc count. Also note that there might also be a discrepancy in the case that you have nested mappings, which create implicity documents. Kibana not showing all documents in index.
You could have one document per product or one document per order. There is no limit to how many documents you can store in a particular index. Data in documents is defined with fields comprised of keys and values.
You can use cURL in a UNIX terminal or Windows command prompt, the Kibana Console UI, or any one of the various low-level clients available to make an API call to get all of the documents in an Elasticsearch index. All of these methods use a variation of the GET request to search the index.
The track_total_hits parameter allows you to control how the total number of hits should be tracked. Given that it is often enough to have a lower bound of the number of hits, such as "there are at least 10000 hits", the default is set to 10,000 .
I found this in the examples that I attach below
es=Elasticsearch([{'host':'url','port':'9200','timeout':60}])
res = es.count(index='your index', doc_type='your doc_type', body={'query': your query })["count"]
If it helps you, here are good examples of count with Python:
https://python.hotexamples.com/examples/elasticsearch/Elasticsearch/count/python-elasticsearch-count-method-examples.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With