Skip to content

Instantly share code, notes, and snippets.

@hscells
Last active August 10, 2017 23:30
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 hscells/774e112d14e3f249e8960d7147d61353 to your computer and use it in GitHub Desktop.
Save hscells/774e112d14e3f249e8960d7147d61353 to your computer and use it in GitHub Desktop.
Start Elasticsearch, 
Index & Query
# 1. Start Elasticsearch
# ./bin/elasticsearch, docker run ...
# 2. Create index
# https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
curl -X PUT http://localhost:9200/example
# => {"acknowledged":true,"shards_acknowledged":true}
# 3. Add a document
# https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html
curl -X POST http://localhost:9200/example/doc -H 'Content-Type: application/json' -d '{"title": "elastic4IR", "body": "Welcome to the workshop!"}'
# =>
# {
# "_index" : "example",
# "_type" : "doc",
# "_id" : "AV3OdFAZ7fqYee2bfgSQ",
# "_version" : 1,
# "result" : "created",
# "_shards" : {
# "total" : 2,
# "successful" : 1,
# "failed" : 0
# },
# "created" : true
# }
# 4. Search for our new document
# https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-all-query.html
curl -X GET http://localhost:9200/example/_search -H 'Content-Type: application/json' -d '{"query": {"match_all": {}}}'
# =>
# {
# "took" : 2,
# "timed_out" : false,
# "_shards" : {
# "total" : 5,
# "successful" : 5,
# "failed" : 0
# },
# "hits" : {
# "total" : 2,
# "max_score" : 1.0,
# "hits" : [
# {
# "_index" : "example",
# "_type" : "doc",
# "_id" : "AV3OdFAZ7fqYee2bfgSQ",
# "_score" : 1.0,
# "_source" : {
# "title" : "elastic4IR",
# "body" : "Welcome to the workshop!"
# }
# }
# ]
# }
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment