As part of this tutorial, we will be creating index, sync, fetch, delete data/document with Elasticsearch with the help of postman.
At the end of the blog, provided the link to download the Postman collection.
Follow below steps to perform various CRUD operations:
Index creation is similar to creation of table in SQL. Follow below step by step process to create index and update data.
3. Setup below headers under Headers tab
Postman-Token → <calculated when request is sent>
Content-Length → 0
Host → <calculated when request is sent>
User-Agent → PostmanRuntime/7.32.3
Accept → */*
Accept-Encoding → gzip, deflate, br
Connection → keep-alive
4. Select body tab having JSON option selected in dropdown and paste below code inside body section to provide index definition.
As part of this index definition, firstName is of type as text and autocomplete. firstName field we are going to use for autocomplete search.
lastName and age are normal text fields.
5. Click on the send button will create an index with the name of practice-index-en
6. To verify the same hit url and click on Open button on home page.
7. Click on the below highlighted Enterprise Search option as shown below.
8. Selection of below indices option will help you to see created index as practice-index-en
Use same API URL with method type as GET and empty body will help us to get the index definition as shown below.
Update the method type to delete will help you to delete the created index in earlier step.
Use below postman call to sync/post/save data to Elasticsearch.
Set method type as PUT and enter below URL
Set body to below JSON object
Click on Send button will POST/sync/save data in Elasticsearch, response code as 201 and result as created.
Let’s verify the same in cloud Elasticsearch, select indices and select Documents tab to see saved/created record.
Note: Same call can be used to update data within Elasticsearch as it is a PUT call.
Use same API URL with method type as GET and empty body will help us to get the document for id as doc1 mentioned as part of URL.
Updating URL to below one will help us to fetch document from Elasticsearch. It will check all indexed fields having ‘khan’ as part of it and return same in the result.
Autocomplete search returns result as soon as we starts typing and fetch all matched results.
Below is the request body to fetch autocomplete data.{
Specialist Master (Architect) with a passion for cutting-edge technologies like AEM (Adobe Experience Manager) and a proven track record of delivering high-quality software solutions.
📝 Blogs
javadoubts.com © All rights reserved