Skip to content

Instantly share code, notes, and snippets.

@scaratec
Last active September 24, 2015 15:04
Show Gist options
  • Save scaratec/17ceb5146d3c104b072a to your computer and use it in GitHub Desktop.
Save scaratec/17ceb5146d3c104b072a to your computer and use it in GitHub Desktop.
Elasticsearch code snippets

Cheat Sheet Elasticsearch

Json-Editor

Show status:

    curl -X GET http://localhost:9200/

Show all indexes:

    curl -X GET 'localhost:9200/_cat/indices?v'

Show all types:

    curl -X GET http://localhost:9200/landaumedia/_all/mappings

Create index:

    curl -X PUT http://localhost:9200/gdg?pretty             

Delete index:

    curl -X DELETE http://localhost:9200/gdg?pretty

Create Document:

    curl -X PUT http://localhost:9200/gdg/article/_create -d '{}'                        

List all Articles:

    curl -X GET http://localhost:9200/gdg/article/_search?pretty        

Simple Search:

    curl -X GET 'http://localhost:9200/gdg/_search?q=content:facebook'

Fuzzy Search:

    curl -X GET http://localhost:9200/gdg/article/_search?pretty -d '
    { "query" :
        {
            "fuzzy" : { "content" : "facbook" }
        }
    }'      

Highlight

    curl -X GET http://localhost:9200/gdg/article/_search?pretty -d '
    {
      "query": {
        "fuzzy": {
          "content": "facbook"
        }
      },
      "highlight": {
        "fields": {
          "content": {}
        }
      }
    }
    '

Date Range Query

    curl -X GET http://localhost:9200/gdg/article/_search?pretty -d '
    {
      "query": {
        "range": {
          "datePublished": {
            "gte": "2015-09-23",
            "lt": "now"
          }
        }
      }
    }'        
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment