Skip to content

Instantly share code, notes, and snippets.

@xemoe
Created October 9, 2015 10:11
Show Gist options
  • Save xemoe/5cb183c84c6092eda6f9 to your computer and use it in GitHub Desktop.
Save xemoe/5cb183c84c6092eda6f9 to your computer and use it in GitHub Desktop.
Elasticsearch documents

Executing a search

ElasticSearch was born as a search engine. Its main work is to process queries and give results. As we'll see in this recipe, search in ElasticSearch is not only limited to match some documents, but also to calculate additional information required to improve user experience.

The HTTP method used to execute a search is GET (but POST also works), the REST URLS are as follows:

http://<server>/_search
http://<server>/<index_name(s)>/_search
http://<server>/<index_name(s)>/<type_name(s)>/_search

Command

curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search' -d '${QUERY}'
{
    "query":{
        "match_all":{}
    }
}
{
    "took": 0,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 1.0,
        "hits": [{
            "_index": "test-index",
            "_type": "test-type",
            "_id": "1",
            "_score": 1.0,
            "_source": {
                "position": 1,
                "parsedtext": "Joe Testere nice guy",
                "name": "Joe Tester",
                "uuid": "11111"
            }
        }]
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment