To index a document using the Elasticsearch REST API, you can send a POST request to the index endpoint with the document data in the request body. Here’s an example of a simple POST request to index a document in an index called “my_index”:
POST http://localhost:9200/my_index/_doc { "title": "Product A", "description": "This is the description of Product A.", "price": 100.0 }
In this example, the POST request includes a request body that contains the document data. The document has a “title” field with the value “Product A”, a “description” field with the value “This is the description of Product A.”, and a “price” field with the value 100.0.
When you send this request, Elasticsearch will create a new document in the “my_index” index with the specified data. The document will be assigned a unique ID by Elasticsearch, or you can specify a custom ID by including an “_id” field in the request body.
Note that you can also use the Elasticsearch API to update, delete, or retrieve documents in your index. The API provides a wide range of options for managing your documents and performing complex searches and queries.