...

Search Engine - Elastic Search

Back to Course

Lesson Description


Lession - #128 Elasticsearch Populate


Elasticsearch Populate

In this part, we will figure out how to add list, record, information, and planning to the elasticsearch data set by utilizing an elasticsearch-head module that we set up in past section. We will execute the questions utilizing this module. Prior to making a solicitation, make certain to run the elasticsearch server utilizing the elasticsearch.bat record. Create an Index To make a list, we want to determine the file name and solicitation strategy. Accordingly, utilize the PUT demand strategy and execute the accompanying order to make a file -

PUT student  
Here PUT is request method and student is index name.
Response Assuming the record is effectively made, you will get the accompanying result in the reaction body

{  
"acknowledged": true,  
"shards_acknowledged": true,  
}  
"index": "student"  


Create a document or Add data

After creating an index, we can now index the document to elasticsearch We will use the POST method for this and specify some IDs for documents to identify them. Set request method = POST.

POST student/_doc/01/  
{  
"name": "Alen Paul",  
"gender": "Male",  
"phone": "9876543210",  
"street": "Malen Park", "city": "California", "country": "United States", "zip": "94025"  
}  
Here POST is request method and _doc is used for document type to add data in the index.

Response The information gave in demand are effectively added on the off chance that you get the accompanying result accordingly body.

{   
"index": "student",  
"type": "_doc",  
"id": "01",  
"version": 1,  
"result" "created",  
"_shards": {  
"total":2,  
"successful":1,  
}  
"failed": 0,  
"_seq_no": 0,  
"_primary_term": 1  
}  




Presently we will add another report in record "understudy". Likewise, we can add quite a few records in a file.

POST student/_doc/02/  
{  
"name": "Stan Lee",  
"gender": "Male",  
"phone": "9876543211",  
"street": "New Rochelle", "city": "New York", "country": "United States", "zip": "10029"  
}  

Response

Another archive is effectively added assuming you get the accompanying result accordingly body.

{   
"index": "student",  
"type": "_doc",  
"id": "02",  
"version": 1,  
"result" "created",  
"_shards": {  
"total":2,  
"successful":1,  
"failed": 0,  
}  
"_seq_no": 1,  
"_primary_term": 2  
}  




Presently go to the Overview tab to see that the information is really added or not. Here invigorate the UI by tapping on the Refresh button. You will ready to see that the record is added containing two archives, which we added already.



Update a document

To refresh a record, we require API, demand strategy, information for update, and solicitation string. Elasticsearch gives _update API to refresh the records. In this model, we will supplant the city from New York to Los Angeles. In this way, utilize the accompanying code to refresh the report.

POST student/_doc/02/  
_update  
{  
"doc": {  
"city": "Los Angeles"  
}  
}  


Response

Assuming that you get a similar result, the archive is refreshed effectively.

{   
"index": "student",  
"type": "_doc",  
"id": "02",  
"version": 2,  
"result": "updated",  
"shards": {  
"total": 2  
"successful": 1  
"failed": 0,  
}  
"_seq_no": 2,  
"_primary_term": 3  
}  
Look at the below screenshot to see the result visually -



Delete a document

Elasticsearch gives a DELETE demand technique to erase a report. Thus, just set the DELETE the solicitation strategy and give file name and archive id.

DELETE student/_doc/01/  


Response

Assuming you get the underneath yield, record 01 is erased effectively.

{   
"index": "student",  
"type": "_doc",  
"id": "01",  
"version": 2,  
"result": "deleted",  
"shards": {  
"total": 2  
"successful": 1  
"failed": 0,  
}  
"_seq_no": 3,  
"_primary_term": 3  
}  





Delete an Index

To erase a list, simply determine the file name and DELETE demand strategy and snap on Request button.

DELETE student