Last active
August 10, 2017 23:30
-
-
Save hscells/774e112d14e3f249e8960d7147d61353 to your computer and use it in GitHub Desktop.
Start Elasticsearch,
Index & Query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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