Using the HTTP protocol

This recipe shows us the usage of the HTTP protocol with an example.

Getting ready

You need a working instance of the ElasticSearch cluster. Using default configuration, ElasticSearch enables port number 9200 on your server to communicate in HTTP.

How to do it...

The standard RESTful protocol is easy to integrate.

We will see how easy it is to fetch the ElasticSearch greeting API on a running server on port 9200 using different programming languages:

  • In BASH, the request will be:
    curl –XGET http://127.0.0.1:9200
    
  • In Python, the request will be:
    import urllib
    result = urllib.open("http://127.0.0.1:9200")
  • In Java, the request will be:
    import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import ...

Get ElasticSearch Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.