Useful Elasticsearch Tips, Tools and commands

Posted 3 weeks ago

Delete all indexes


curl -X DELETE 'http://localhost:9200/_all'

Get the mapping and the settings

GET /index_name/_mapping
GET /index_name/_settings

Import data VIA curl into Elastic

curl -H "Content-Type: application/json" -XPOST "http://localhost:9200/INDEX-PATH/_bulk?pretty" --data-binary @path/to/file/test.json

Aggregations


GET /index/type/_search 
{
  "query": {
    "match": {
      "name": "SEARCH_TERM"
    }
  },
  "size": 0, 
  "aggs": {
    "quantity_sum": {
      "sum": {
        "field": "price"
      }
    }
  }
}

Multiple Aggregations Returned


GET /index/type/_search 
{
  "query": {
    "match": {
      "name": "SEARCH_TERM"
    }
  },
  "size": 0, 
  "aggs": {
    "quantity_stats": {
      "stats": {
        "field": "price"
      }
    }
  }
}

List all indices


GET /_cat/indices

List everything


GET _search
{
  "query": {
    "match_all": {}
  }
}