Skip to content

Instantly share code, notes, and snippets.

@knutwalker
Created October 17, 2012 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knutwalker/3905668 to your computer and use it in GitHub Desktop.
Save knutwalker/3905668 to your computer and use it in GitHub Desktop.
Simplest ES creation
# start...
$ bin/elasticsearch
# ... with nothing
$ curl -XDELETE localhost:9200
{"ok":true,"acknowledged":true}
# index document
$ curl -XPUT http://localhost:9200/index1/type1/id1 -d '{"title": "foo", "tags": ["bar", "baz"]}'
{"ok":true,"_index":"index1","_type":"type1","_id":"id1","_version":1}
# get the document
$ curl -XGET http://localhost:9200/index1/type1/id1
{"_index":"index1","_type":"type1","_id":"id1","_version":1,"exists":true, "_source" : {"title": "foo", "tags": ["bar", "baz"]}}
# search the document
$ curl http://localhost:9200/index1/type1/_search?q=foo
{"took":43,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":0.15342641,"hits":[{"_index":"index1","_type":"type1","_id":"id1","_score":0.15342641, "_source" : {"title": "foo", "tags": ["bar", "baz"]}}]}}
# pretty search
$ curl -s http://localhost:9200/index1/type1/_search?q=foo | python -mjson.tool
{
"_shards": {
"failed": 0,
"successful": 5,
"total": 5
},
"hits": {
"hits": [
{
"_id": "id1",
"_index": "index1",
"_score": 0.15342641,
"_source": {
"tags": [
"bar",
"baz"
],
"title": "foo"
},
"_type": "type1"
}
],
"max_score": 0.15342641,
"total": 1
},
"timed_out": false,
"took": 11
}
# or prettify via ES
$ curl 'http://localhost:9200/index1/type1/_search?q=foo&pretty'
{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.15342641,
"hits" : [ {
"_index" : "index1",
"_type" : "type1",
"_id" : "id1",
"_score" : 0.15342641, "_source" : {"title": "foo", "tags": ["bar", "baz"]}
} ]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment