ElasticSearch Commands
Elasticsearch is a search engine based on the Lucene library. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents. Elasticsearch is developed in Java.
To run and test the ES I will be using docker.Here are the steps to run the ES locally:
http://thebadengineer.com/docker-compose/
To view if its running send a GET request to the https://localhost:9201/ and the response is given below:
{ "name": "node-1", "cluster_name": "elasticsearch", "cluster_uuid": "iSwT1P8DTEC7ZzM_oFD6OA", "version": { "number": "7.3.2", "build_flavor": "default", "build_type": "tar", "build_hash": "1c1faf1", "build_date": "2019-09-06T14:40:30.409026Z", "build_snapshot": false, "lucene_version": "8.1.0", "minimum_wire_compatibility_version": "6.8.0", "minimum_index_compatibility_version": "6.0.0-beta1" }, "tagline": "You Know, for Search" }
Command Used for searching and its response are :
- To search for all the indices:
https://localhost:9201/_cat/indices/
response is : the list of all index - To search for the aliases:
https://localhost:9201/_cat/aliases/
response is : alias name of the original index - To query for the all records in particular index:
https://localhost:9201/index_1/_doc/_search
response is:all the records in that index - To query for the all records for a field like tenantId in particular index:
and we have to send a GET request as a body.
https://localhost:9201/index_1/_doc/_search and set body as down below:
{ "query" :{ "match" : { "tenantId" : "sample-tenantId" } } }
- To delete all records at particular index :
do a POST request to https://localhost:9201/index_1/_delete_by_query and set body as below:
{ "query": { "match_all": {} } }
- To get all the records in the particular index:
do a POST request https://localhost:9201/index_1/
{ "query": { "match_all": {} } }
- Alternative type of query to get the records:
Give all the recods
{ "query": { "bool": { "must": [ { "bool": { "must": [ { "bool": { "must": [ { "term": { "type": { "value": "Order", "boost": 1 } } }, { "term": { "tenantId": { "value": "randomId, "boost": 1 } } } ], "adjust_pure_negative": true, "boost": 1 } } ], "adjust_pure_negative": true, "boost": 1 } } ], "must_not": [ { "term": { "deleted": { "value": true, "boost": 1 } } } ], "should": [ { "bool": { "adjust_pure_negative": true, "boost": 1 } } ], "adjust_pure_negative": true, "boost": 1 } }, "sort": [ { "updateReceived": { "order": "desc" } }, { "_id": { "order": "desc" } } ], "search_after": [ "", "oN5j1HYBGmqozEEFlDXY" ] }
Your posts provide a clear, concise description of the issues. Laura Galvin Krys