Curl and elasticSearch

By | February 21, 2017

One of the most useful utilities is “curl”. This wonderful tool can be used to transfer data from one platform to another. It is relatively easy to install in Windows, whereas under linux, it is often already installed. It must be run from the terminal in Linux or the command line in Windows. One example is transfer of data from a webserver. But other protocols can be used as well: ftp, file, pop3 etc.

 

An example is given below. One sees the command line that is used to invoke the curl utility. Curl is invoked by typing “curl”. The first parameter is the host that must be accessed. In this case I will access a webserver from which the data are retrieved. In this case, I will access www.van-maanen.com, my own website. Doing so, I transfer the html that is generated from the webserver.

 

 

A similar statement can be user to retrieve data from a FTP server. Take as example: curl ftp://192.168.2.2 –user tom.vanmaanen@wxs.nl:tom24567 . This will open a FTP server.

We may use curl to add data into ElasticSearch. Doing so, we transfer data from a local platform to the ElasticSearch database. We use this command from the windows platform: curl -XPUT “192.168.2.11:9200/movies/soort/123563458”  -d”{“”title””:””TestTom”” , “”director””:””Tom van Maanen””,””year””: 1957}”. Note: from linux the aspostophes are different. There the command should be curl -XPUT ‘192.168.2.11:9200/movies/soort/123563459′  -d'{“title”:”TestTom” , “director”:”Tom van Maanen”,”year”: 1957}’. On windows, we see:

 

The reaction from ElasticSearch (“created”:true) indicates that the record is correctly inserted.

 

In a similar exercise, we may retrieve records from the ElasticSearch database. We use: curl -XGET “192.168.2.11:9200/movies/soort/_search” -d “{“”query”” : {“”match”” : {“”title”” : “”TestTom””}}}”.

 

We get something like:

 

 

We see the same records that we inserted.