Basic Query in Amazon Elasticsearch Service

Ankit Kumar Rajpoot
3 min readSep 28, 2020
Elastic Search

Amazon Elasticsearch Service is a managed service that makes it easy to deploy, operate, and scale Elasticsearch in the AWS Cloud. Elasticsearch is a popular open-source search and analytics engine for use cases such as log analytics, real-time application monitoring, and clickstream analytics.

You will click on your endpoint then you will be got this type of output. It means your connectivity has established.

Connection

Post Data(Create Data in index):-

Where:- test is index and _doc is a document.

$ curl -XPOST --header 'Content-Type: application/json' https://search-testarticle-2cwv6oh7wtz3hxowgxv3rprnsa.ap-south-1.es.amazonaws.com/Amazon Elasticsearch Service/_doc -d '{
"skills" : [
"a"
],
"name" : "Ankit Rajpootttt",
"email" : "rajputankit22@gmail.com",
"address" : {
"address" : "A/27 Bhopal",
"city" : "Bhopal",
"pin" : 487551,
"state" : "M.P."
},
"dob" : "2019-12-11T00:00:00.000Z",
"higerEducation" : "MCA"
}'
Post Data

Search all document without Index

$ curl -XGET --header 'Content-Type: application/json' https://search-testarticle-2cwv6oh7wtz3hxowgxv3rprnsa.ap-south-1.es.amazonaws.com/_search
Search Without Index

Search all data with Index

Where:- test is index name.

$ curl -XGET --header 'Content-Type: application/json' https://search-testarticle-2cwv6oh7wtz3hxowgxv3rprnsa.ap-south-1.es.amazonaws.com/test/_search
Search With Index

Universal search:- In this search text will be matched in each field.

Where:- test is index name and Ankit is a searching text.

$ curl -XGET --header 'Content-Type: application/json' https://search-testarticle-2cwv6oh7wtz3hxowgxv3rprnsa.ap-south-1.es.amazonaws.com/test/_search\?q=Ankit
Search in all fields

Search value in a single field

$ curl -XGET --header 'Content-Type: application/json' https://search-testarticle-2cwv6oh7wtz3hxowgxv3rprnsa.ap-south-1.es.amazonaws.com/test/_search\?q=name:Rajpootttt
Search through a field

Search through id with query

curl -XGET --header 'Content-Type: application/json' https://search-testarticle-2cwv6oh7wtz3hxowgxv3rprnsa.ap-south-1.es.amazonaws.com/test/_search\?q=_id:4gI4knQB7d5sAgV24YPy
Search with id

Search through id without query

curl -XGET --header 'Content-Type: application/json' https://search-testarticle-2cwv6oh7wtz3hxowgxv3rprnsa.ap-south-1.es.amazonaws.com/test/_doc/4gI4knQB7d5sAgV24YPy
Search with id

Delete a document from index through the id

curl -XDELETE --header 'Content-Type: application/json' https://search-testarticle-2cwv6oh7wtz3hxowgxv3rprnsa.ap-south-1.es.amazonaws.com/test/_doc/ogLWkXQB7d5sAgV2AIMf
Delete document

Update object through id

curl -XPUT --header 'Content-Type: application/json' https://search-testarticle-2cwv6oh7wtz3hxowgxv3rprnsa.ap-south-1.es.amazonaws.com/test/_doc/4gI4knQB7d5sAgV24YPy -d '{
"skills" : [
"a"
],
"name" : "Ankit Singh",
"email" : "ankit@gmail.com",
"address" : {
"address" : "A/27 Bhopal",
"city" : "Bhopal",
"pin" : 487551,
"state" : "M.P."
},
"dob" : "2019-12-11T00:00:00.000Z",
"higerEducation" : "MCA"
}'
Update Object

Update single field through id

$ curl -XPOST --header 'Content-Type: application/json' https://search-testarticle-2cwv6oh7wtz3hxowgxv3rprnsa.ap-south-1.es.amazonaws.com/test/_update/4gI4knQB7d5sAgV24YPy -d '{"doc":{    "name" : "Ankit Singh Raj"}}'
Update field

That’s it for this time! I hope you enjoyed this post. As always, I welcome questions, notes, comments and requests for posts on topics you’d like to read. See you next time! Happy Coding !!!!!

--

--

Ankit Kumar Rajpoot

I’m a MERN Developer. ( Redux | AWS | Python ) I enjoy taking on new things, building skills, and sharing what I’ve learned.