Skip to content

Instantly share code, notes, and snippets.

@ps-przemekaugustyn
Last active August 1, 2021 02:19
Show Gist options
  • Save ps-przemekaugustyn/bec11f45f1badb7ac53efa4eac641833 to your computer and use it in GitHub Desktop.
Save ps-przemekaugustyn/bec11f45f1badb7ac53efa4eac641833 to your computer and use it in GitHub Desktop.
Elasticsearch cheatsheet
GET _search
{
  "query": {
    "match_all": {}
  }
}

GET /_template
GET /_template/template_1

GET /_cat/indices?format=json
GET /*/_stats

# DELETE /product-2021-02-08
GET /product-2021-02-08/_mapping
GET /product-2021-02-08/_mapping/field/date

GET /marketplace-2021-03-23/_mapping?include_type_name=true

GET /product*/_search
GET /product-2021-02-08/_search
{
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
        "range": {
          "dates.date_checked": {
            "gte": "2021-01-27T00:00:20Z",
            "lt": "2021-01-27T18:19:50Z"
          }
        }
      }
    }
  }
}

GET /product-2021-02-08/_search
{
  "_source": false,
  "query": {
    "bool": {
      "must": {
        "match_all": {}
      },
      "filter": {
        "range": {
          "dates.date_checked": {
            "gte": "2021-01-27T00:00:20Z",
            "lt": "2021-01-27T18:19:50Z"
          }
        }
      }
    }
  }
}
GET /.kibana/_search?q=type:index-pattern 
{
  "docvalue_fields": ["index-pattern.title.keyword"],
  "_source": false
}

GET .kibana/_doc/index-pattern:630dae20-880f-11eb-96f4-1fc398b97b1f

GET .kibana/_search?size=100
{
    "query": {
        "match_all": {}
    }
}

GET /.kibana/_search?q=type:visualization 
POST product-2021-02-08/_doc
{
  "signature":"something",
  "title": "this is the product title",
   "dates": {
      "date_checked": "2021-01-27 18:19:36",
      "date_requested": "2021-01-27 21:20:14"
        
    }
}

POST product-2021-02-08/_doc
{
  "title": "this is the product title",
   "dates": {
        "date_checked": "2021-01-27T03:00:10.000005",
        "date_requested": "2021-01-27 21:20:14"
    }
}
PUT _template/template_1
{
  "index_patterns": ["product-*"],
  "mappings":{
   "_source":{
     "excludes":[
       "signature"]
   },
    "properties":{
      "dates" : {
            "properties" : {
              "date_checked" : {
                "type" : "date",
                "format" : "yyyy-MM-dd HH:mm:ss||strict_date_optional_time"
              },
              "date_requested" : {
                "type" : "date",
                "format" : "yyyy-MM-dd HH:mm:ss||strict_date_optional_time"
              }
            }
          }
    }
  }
}

PUT _template/template_1
{
  "index_patterns": ["product-*"],
  "mappings":{
    "properties":{
      "dates" : {
            "properties" : {
              "date_checked" : {
                "type" : "date",
                "format" : "strict_date_optional_time"
              },
              "date_requested" : {
                "type" : "date",
                "format" : "yyyy-MM-dd HH:mm:ss||strict_date_optional_time"
              }
            }
          }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment