Book Image

ElasticSearch Cookbook

By : Alberto Paro
Book Image

ElasticSearch Cookbook

By: Alberto Paro

Overview of this book

Table of Contents (20 chapters)
ElasticSearch Cookbook Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Managing bulk actions


Executing atomic operation on items via single call is often a bottleneck if you need to index or delete thousands/millions of records. The best practice in this case is to execute a bulk action. We have discussed bulk action via the REST API in the Speeding up atomic operations (bulk operations) recipe in Chapter 4, Basic Operations.

Getting ready

You will need a working ElasticSearch cluster and Maven installed.

The code of this recipe is in chapter_10/nativeclient in the code bundle of this chapter, which is available on Packt's website, and on GitHub (https://github.com/aparo/elasticsearch-cookbook-second-edition). The referred class is BulkOperations.

How to do it...

To manage a bulk action, we will perform the following actions:

  • We'll execute a bulk action adding 1,000 documents, updating them and deleting them as follows:

    import org.elasticsearch.action.bulk.BulkRequestBuilder;
    import org.elasticsearch.client.Client;
    import org.elasticsearch.common.xcontent.XContentFactory...