Curl To Postman



Let’s learn how to create an index in elasticsearch with different configurations.

Online curl command line builder. Easily generate curl command lines to test your new shining API or whatever! GET POST PUT PATCH DELETE URL Body. Header key Header.

Typeform, Bukalapak, and PedidosYa are some of the popular companies that use Postman, whereas cURL is used by Kosada, mytaxi, and immmr. Postman has a broader approval, being mentioned in 1755 company stacks & 2238 developers stacks; compared to cURL, which is listed in 5 company stacks and 7 developer stacks. As mentioned, I will be using curl to simulate HEAD, GET, POST, PUT and DELETE request calls against a REST API. HEAD requests If you want to check if a resource is serviceable, what kind of headers it provides and other useful meta-information written in response headers, without having to transport the entire content, you can make a HEAD request.

In Elasticsearch an index is equivalent to database in relational database. An index can contain multiple documents and in elasticsearch there can be multiple indices.

Create an Index in Elasticsearch with default shards and replicas

Curl

Elasticsearch provides a Create Index API to manually create index by sending PUT request. Suppose our elasticsearch is running at localhost and at port 9200. Let’s see how to create an index in elasticsearch with different configuration,

Curl

Create an Index in Elasticsearch with default shards, replicas

Using Curl command :

Let’s create an index with name userindex1 in Elasticsearch with default settings i.e.

Output of this command will be,

Curl

It basically created an index with default number of shards i.e. 5, default number replicas i.e. 1 and with default empty mapping. Once the create index API returns all the shards are ready to accept data and all nodes are updated with index status.

Using POSTMAN :

We can also execute the same command using POSTMAN i.e.

We can check the status of created index with following command,

Curl To Postman

This command will return a JSON string containing the information about the index userindex1 i.e.

As we can see that default value for the number of shards and replicas has been chosen i.e. 5 and 1 respectively.

Creating an index that already exists

If an index with given name already exists and we again try to create that then it will thought error 400. For example, let’s try to create index userindex1 again i.e.

As index userindex1 already exists, so this will return an error in the returned JSON string i.e.

Here status is 400 and error reason is “index [userindex1/f2_Oqzr0SwiGWdDn_HiiKQ] already exists”.

Create an Index in Elasticsearch with custom shards and replicas

While creating an index in elasticsearch we can also specify the number of shards and replicas of the index in cluster.

This command will return following JSON string,

Which tells the index userindex2 is created successfully. Here we passed the 2 attributes in the settings number_of_shards and number_of_replicas, they represents the count of shards and replicas in index. Therefore, it created index userindex2 with 2 shards and 1 replica.

Post

you confirm that by using following command to check the status of created index with following command,

Import Curl To Postman

Create index in Elasticsearch with mapping

Till now we have discussed ways to create an index without any mapping. Let’s create a new index and also pass mapping of while creating index. For this we need to pass the mappings field along with settings i.e.

This command will return the following JSON string,

It will create the index with given mapping. We can do same using POSTMAN too i.e.

Check the mapping of created index

Once created we can confirm the mapping of created index by executing following command,

Curl post to postman

It will return the complete mapping of index userindex4 in a JSON record i.e.