ElasticSearch curl get request to search a record

The Elasticsearch GET API helps us retrieve specific information stored in an Elasticsearch index. It allows users to search for records using different details, such as a student's name, school, age, or unique ID. We can send a GET request with the required search condition, and Elasticsearch will look for matching documents in the specified index. The results are returned in JSON format, making the information easy to read and understand. We can use this API to find one or more records without having to retrieve all the data from the index. For example, if we want to find a student named John, we can provide the student's name in the search query, and Elasticsearch will return the matching student details.


curl -X GET "http://localhost:9200/samples/_search?q=name:John"
This command is used to search for a student by name in Elasticsearch. Here, curl sends a GET request to the Elasticsearch server running on your local machine (localhost:9200). The samples represents the index where student records are stored, and _search tells Elasticsearch to search within that index. The q=name:John part tells Elasticsearch to find student records where the name field matches John. Finally, Elasticsearch returns the matching student details in JSON format.

FAQ 1. What is Elasticsearch GET API? It is used to retrieve information from an Elasticsearch index. 2. What is the purpose of _search? It tells Elasticsearch to search for documents in the specified index.