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

Creating an HTTP client


An HTTP client is one of the easiest clients to create. It's very handy because it allows calling not only internal methods as the native protocol does, but also third-party calls implemented in plugins that can be called only via HTTP.

Getting ready

You will need a working ElasticSearch cluster and Maven installed. The code of this recipe is in the chapter_10/http_client directory, present in the code bundle available on the Packt website and on GitHub (https://github.com/aparo/elasticsearch-cookbook-second-edition).

How to do it...

To create an HTTP client, we will perform the following steps:

  1. For these examples, we have chosen the Apache HttpComponents, one of the most widely used libraries for executing HTTP calls. This library is available in the main Maven repository search.maven.org. To enable compilation in your Maven pom.xml project, just add:

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId...