ElasticSearch – How to Interact with ElasticSearch using JSON over HTTP ?

Published on March 5, 2016 by abundantcode

Filed under Elastic Search

Last modified March 5, 2016

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 4385 times

Problem Statement

You need to communicate with ElasticSearch to perform the search or the CRUD operations.


You can interact with ElasticSearch using the RESTful API over port 9200.

Additionally , ElasticSearch has the official clients for various programming languages like .NET , Java , Ruby etc.

The format of the request of ElasticSearch is as specified below.


Additionally , it can contain the request body.

1. The VERB can be GET , POST , PUT , HEAD , DELETE.

2. Protocol can be http or https

3. HOST refers to the host name of the elasticsearch cluster . Eg : localhost

4. PORT – This refers to the port number where the ElasticSearch is running. The default port number where ElasticSearch runs in 9200.

5. QUERYSTRING is the optional query string parameters used for the request URL.

6. The body contains the JSON encoded request body (if needed).

When testing the ElasticSearch API , you might want a graphical client like Fiddler or Chrome Sense plug-in to try,

Chrome plug-in called "Sense" is a excellent tool to test ElasticSearch API. It provides a simple user interface for using the ElasticSearch REST API. Some of the features include autocomplete for queries , copy and paste the request in curl format etc. 

You can search for the Sense plugin from your Google Chrome browser and install it.

Once you have installed the Sense plugin , you will see its icon in the upper right corner in Google Chrome. Just tap on the icon and you are ready to start.


The Query can be entered in the left sidebar. The response will be shown in the content area.

This is the query in curl which displays the number of documents in the ElasticSearch cluster

curl -XGET 'http://localhost:9200/_count?pretty' -d ' 
        "match_all": {}    

The response of the above query is

   "count": 10,
   "_shards": {
      "total": 15,
      "successful": 15,
      "failed": 0

Leave a Comment


You might be Interested in these Posts

C# Program to swap two numbers without using temporary variable

Problem Write a program in Visual CSharp to swap two numbers using temporary variable and display t...

C# Program to swap two numbers

Problem Write a program in C# to swap two numbers using temporary variable and display the result i...

C# Program to print the sum of two numbers

Problem Write a program in C# to add two numbers and display the result in copnsole window. How to...