Before deploying Elasticsearch, ensure that the Java Development Kit (JDK) is installed and the JAVA_HOME environment variable is correctly configured. Once the environment is ready, download the Elasticsearch Windows distribution and extract it to your preferred directory.
Starting the Service
Navigate to the bin directory within the extracted folder and execute the batch file to start the node:
cd C:\elasticsearch-7.5.0\bin
elasticsearch.bat
Once the initialization is complete, verify the node is running by accessing the default endpoint in your web browser:
http://localhost:9200/
Indexing a Document
To add a new record (document) to an index named films with a specific ID, use the following curl command. Note that JSON data passed in the command line requires double quotes to be escaped with a backslash (\).
curl -H "Content-Type: application/json" -XPUT "http://localhost:9200/films/drama/1" -d "{\"title\": \"The Godfather\",\"director\":\"Francis Ford Coppola\",\"year\": 1972}"
Retrieving a Document
To fetch the document created above using its ID:
curl -H "Content-Type: application/json" -XGET "http://localhost:9200/films/drama/1"
Deleting a Document
To remove a document from the index:
curl -XDELETE "http://localhost:9200/films/drama/1"
Search Operations
You can query data across the entire cluster or specific scopes using the _search API.
Search all indices:
curl -XGET "http://localhost:9200/_search"
Search within a speciifc index:
curl -XGET "http://localhost:9200/films/_search"
Search within a specific index and type:
curl -XGET "http://localhost:9200/films/drama/_search"
Troubleshooting Common Errors
- Error 406:
Content-Type header [application/x-www-form-urlencoded] is not supported
Solution: Ensure you include the header-H "Content-Type: application/json"in your curl request. - Error 400:
mapper_parsing_exception/Unexpected end-of-input
Solution: This usually occurs because double quotes inside the JSON payload are not escaped. Ensure every internal quote is prefixed with a backslash (e.g.,\"title\").
Cluster and Index Monitoring
Check the health status of the cluster:
http://localhost:9200/_cat/health?v
List all existing indices in the cluster:
http://localhost:9200/_cat/indices?v