elasticsearch
-
pull and run
-
pull
# docker pull elasticsearch
-
simply
# docker run -d -p 9200:9200 9300:9300 --name ges elasticsearch
-
pass flags
# docker run -d elasticsearch -Des.node.name="TestNode"
-
provide config
# docker run -d -v "$PWD/config":/usr/share/elasticsearch/config elasticsearch
-
persist data
# docker run -d -v "$PWD/esdata":/usr/share/elasticsearch/data elasticsearch
-
-
browse http://localhost:9200/
-
output
{ "name" : "Conrad Josten", "cluster_name" : "elasticsearch", "cluster_uuid" : "rFYCofG9QQmEDLLzdVSsOw", "version" : { "number" : "2.4.1", "build_hash" : "c67dc32e24162035d18d6fe1e952c4cbcbe79d16", "build_timestamp" : "2016-09-27T18:57:55Z", "build_snapshot" : false, "lucene_version" : "5.5.2" }, "tagline" : "You Know, for Search" }
-
python with elasticsearch
-
install package
-
run
# pip install elasticsearch
-
from datetime import datetime from elasticsearch import Elasticsearch es = Elasticsearch() doc = { 'author': 'kimchy', 'text': 'Elasticsearch: cool. bonsai cool.', 'timestamp': datetime.now(), } res = es.index(index="test-index", doc_type='tweet', id=1, body=doc) print(res['created']) res = es.get(index="test-index", doc_type='tweet', id=1) print(res['_source']) es.indices.refresh(index="test-index") res = es.search(index="test-index", body={"query": {"match_all": {}}}) print("Got %d Hits:" % res['hits']['total']) for hit in res['hits']['hits']: print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])
-
output
True {u'text': u'Elasticsearch: cool. bonsai cool.', u'author': u'kimchy', u'timestamp': u'2016-10-22T15:56:21.202901'} Got 1 Hits: 2016-10-22T15:56:21.202901 kimchy: Elasticsearch: cool. bonsai cool.
-