{"id":1585,"date":"2017-02-21T11:40:42","date_gmt":"2017-02-21T11:40:42","guid":{"rendered":"http:\/\/62.131.51.129\/?p=1585"},"modified":"2017-02-21T11:40:42","modified_gmt":"2017-02-21T11:40:42","slug":"curl-and-elasticsearch","status":"publish","type":"post","link":"http:\/\/archief.van-maanen.com\/?p=1585","title":{"rendered":"Curl and elasticSearch"},"content":{"rendered":"<p>One of the most useful utilities is &#8220;curl&#8221;. 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.<\/p>\n<p>&nbsp;<\/p>\n<p>An example is given below. One sees the command line that is used to invoke the curl utility. Curl is invoked by typing &#8220;curl&#8221;. 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.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/62.131.51.129\/wp-content\/uploads\/2017\/02\/Untitled-3.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1590\" src=\"http:\/\/62.131.51.129\/wp-content\/uploads\/2017\/02\/Untitled-3.png\" alt=\"\" width=\"356\" height=\"192\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>A similar statement can be user to retrieve data from a FTP server. Take as example:\u00a0curl ftp:\/\/192.168.2.2 &#8211;user tom.vanmaanen@wxs.nl:tom24567 . This will open a FTP server.<\/p>\n<p>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:\u00a0curl -XPUT &#8220;192.168.2.11:9200\/movies\/soort\/123563458&#8221; \u00a0-d&#8221;{&#8220;&#8221;title&#8221;&#8221;:&#8221;&#8221;TestTom&#8221;&#8221; , &#8220;&#8221;director&#8221;&#8221;:&#8221;&#8221;Tom van Maanen&#8221;&#8221;,&#8221;&#8221;year&#8221;&#8221;: 1957}&#8221;. Note: from linux the aspostophes are different. There the command should be\u00a0curl -XPUT &#8216;192.168.2.11:9200\/movies\/soort\/123563459&#8242; \u00a0-d'{&#8220;title&#8221;:&#8221;TestTom&#8221; , &#8220;director&#8221;:&#8221;Tom van Maanen&#8221;,&#8221;year&#8221;: 1957}&#8217;. On windows, we see:<\/p>\n<p><a href=\"http:\/\/62.131.51.129\/wp-content\/uploads\/2017\/02\/Untitled-4.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1596\" src=\"http:\/\/62.131.51.129\/wp-content\/uploads\/2017\/02\/Untitled-4.png\" alt=\"\" width=\"721\" height=\"64\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>The reaction from ElasticSearch (&#8220;created&#8221;:true) indicates that the record is correctly inserted.<\/p>\n<p>&nbsp;<\/p>\n<p>In a similar exercise, we may retrieve records from the ElasticSearch database. We use: curl -XGET &#8220;192.168.2.11:9200\/movies\/soort\/_search&#8221; -d &#8220;{&#8220;&#8221;query&#8221;&#8221; : {&#8220;&#8221;match&#8221;&#8221; : {&#8220;&#8221;title&#8221;&#8221; : &#8220;&#8221;TestTom&#8221;&#8221;}}}&#8221;.<\/p>\n<p>&nbsp;<\/p>\n<p>We get something like:<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/62.131.51.129\/wp-content\/uploads\/2017\/02\/Untitled-5.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1597\" src=\"http:\/\/62.131.51.129\/wp-content\/uploads\/2017\/02\/Untitled-5.png\" alt=\"\" width=\"717\" height=\"171\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>We see the same records that we inserted.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the most useful utilities is &#8220;curl&#8221;. 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1588,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1585","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/1585","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1585"}],"version-history":[{"count":0,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=\/wp\/v2\/posts\/1585\/revisions"}],"wp:attachment":[{"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1585"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/archief.van-maanen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}