Elastic Search

To check health

curl -X GET "localhost:9200/_cat/health"

To list all index (tables)

curl -X GET "localhost:9200/_cat/indices"

To delete existing index

curl -X DELETE localhost:9200/logs

To delete multiple indices at a time

curl -X DELETE localhost:9200/index1,index2,index3

To create new index(table)

curl -X PUT localhost:9200/index1

To insert new document

curl -X POST localhost:9200/users/_doc -H 'Content-Type: application/json' -d '{"name":"Shailesh", "age": 35, "city": "Nagpur"}'

To list all documents

curl -X GET localhost:9200/users/_search?pretty

To limit / size

curl -X GET localhost:9200/users/_search -H 'Content-Type: application/json' -d '{"size":2}'

To add limit with offset

curl -X GET localhost:9200/users/_search -H 'Content-Type: application/json' -d '{"from":3, "size":2}'

To list with where clause and equal operator

curl -X GET localhost:9200/users/_search?pretty -H 'Content-Type: application/json' -d '{"query": {"match": {"name": "Shailesh"}}}'

With like query

curl -X GET localhost:9200/users/_search?pretty -H 'Content-Type: application/json' -d '{"query": {"wildcard":{"name.keyword":"Shail*"}}}'

With range

curl -X GET localhost:9200/users/_search -H 'Content-Type: application/json' -d '{"query": { "range" : {"salary": {"gt": 10000, "lt":30000}} } }'
curl -X GET localhost:9200/users/_search -H 'Content-Type: application/json' -d '{"query": { "range" : {"salary": {"gte": 10000, "lte":30000}} } }'

Select data from more than one index

curl -X GET localhost:9200/table1,table2/_search
curl -X GET localhost:9200/table1,table2/_search -H 'Content-Type: application/json' -d '{"query": {"range": {"salary": {"gt": "20000"}}}}'

This will search data from both the indices and will show all the documents whose salary is greater than 20000

Now the most important command, the full text search

curl -X GET "localhost:9200/users/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "query": {
    "match": {
      "name": {
        "query": "Amit Desai",
        "operator": "and"
      }
    }
  }
}'

This will search amit and desai matches in any order, you can use or operator also if wanted to match any of the word from amit and desai