From 985757ec8d96b0fab32b32b09149f876fc888cf4 Mon Sep 17 00:00:00 2001 From: Ervin Pektor Date: Sat, 14 Mar 2026 12:13:02 +0100 Subject: [PATCH] Add instructions for curl/sed along with PS Powershell is not actually required, the commands can be trivially replaced with curl/sed commands --- docs/elasticsearch/exercise3.md | 24 ++++++++++++++++++++++-- docs/elasticsearch/index.md | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/docs/elasticsearch/exercise3.md b/docs/elasticsearch/exercise3.md index 3b59c47..b391f2d 100644 --- a/docs/elasticsearch/exercise3.md +++ b/docs/elasticsearch/exercise3.md @@ -6,20 +6,30 @@ Now that both _Elasticsearch_ and _Kibana_ are operational, let us create the ne First, we are going to use _Elasticsearch's_ REST API through _PowerShell_. -1. To index a document in _Elasticsearch_, issue the following command. +1. To index a document in _Elasticsearch_, issue the following command in _PowerShell_. ```powershell (Invoke-WebRequest 'http://localhost:9200/test/_doc/1?pretty' -Method Put -ContentType 'application/json' -Body '{ "name": "John Doe" }' -UseBasicParsing).Content ``` + Or to use _cURL_ issue the following. + ```bash + curl -X PUT "http://localhost:9200/test/_doc/1?pretty" -H "Content-Type: application/json" -d '{ "name": "John Doe" }' + ``` + This way, we inserted a document of type `_doc` into the index called `test` with id `1`. The response JSON should state `"result": "created"`. -1. Query the document with the following command. +1. Query the document with the following command in _PowerShell_. ```powershell (Invoke-WebRequest 'http://localhost:9200/test/_doc/1?pretty' -Method Get -UseBasicParsing).Content ``` + Or to use cURL issue the following. + ```bash + curl "http://localhost:9200/test/_doc/1?pretty" + ``` + The result JSON tells us the name of the index, the document's id, and the entire document we inserted in the `_source` field. ```json @@ -164,6 +174,11 @@ Before importing the rest of the sample data, add your **Neptun code** as a pref (Get-Content .\salaries.json) -replace '"gender":"', '"gender":"NEPTUN ' -replace '"company":"', '"company":"NEPTUN ' | Set-Content .\salaries.json ``` + Or to use _sed_ issue the following. + ```bash + sed -i 's/"gender":"/"gender":"NEPTUN /g; s/"company":"/"company":"NEPTUN /g' salaries.json + ``` + 1. Verify the results; it should look similar (with your own Neptun code): ![Replacements in the document](images/replace-data-result.png) @@ -185,6 +200,11 @@ And now, let us index these documents. Invoke-WebRequest 'http://localhost:9200/_bulk' -Method Post -ContentType 'application/json' -InFile .\salaries.json -UseBasicParsing ``` + Or to use _cURL_: + ```bash + curl -X POST "http://localhost:9200/_bulk" -H "Content-Type: application/json" --data-binary @salaries.json + ``` + 1. Check the response for errors. You will see a similar message if everything is OK (note the _errors_ in the response): ![Elasticsearch indices](images/bulk-import-ok.png) diff --git a/docs/elasticsearch/index.md b/docs/elasticsearch/index.md index 7e53ce1..0ff4666 100644 --- a/docs/elasticsearch/index.md +++ b/docs/elasticsearch/index.md @@ -11,7 +11,7 @@ You need the following tools to complete this laboratory: - Either run them using Docker, if you have Docker on your machine - Or you can download the binaries (see in Exercise 2) - You can also use a VM at , see details [here](bme-cloud-vm-usage.md). -- PowerShell +- PowerShell or cURL and sed - Included in Windows - [Install PowerShell Core on Linux](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux) - [Install PowerShell Core on MacOS](https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-macos)