elasticsearch - Indexing and retrieving a document in elasticsearch - elastic - elastic search - elasticsearch tutorial - elasticsearch docker
Indexing and retrieving a document in elasticsearch
Elasticsearch is accessed through a HTTP REST API, typically using the cURL library. The messages between the search server and the client (your or your application) are sent in the form of JSON strings. By default, Elasticsearch runs on port 9200. In the examples below, ?pretty is added to tell Elasticsearch to prettify the JSON response. When using these endpoints within an application you needn't add this query parameter.
Indexing documents
If we intend to update information within an index later, it's a good idea to assign unique IDs to the documents we index. To add a document to the index named megacorp, with type employee and ID 1 run:
Response:
The index is created if it does not exist when we send the PUT call.
Indexing without an ID
Response:
Retrieving documents
Response:
Fetch 10 documents from the megacorp index with the type employee:
Response:
Simple search using the match query, which looks for exact matches in the field provided:
Response: