Visit this link for installation information
https://www.elastic.co/guide/en/elasticsearch/guide/current/_installing_elasticsearch.html
Running and checking in
https://www.elastic.co/guide/en/elasticsearch/guide/current/running-elasticsearch.html
In [1]:
from datetime import datetime
In [2]:
from elasticsearch import Elasticsearch
In [3]:
# by default we connect to localhost:9200
es = Elasticsearch()
In [4]:
# datetimes will be serialized
es.index(index="my-index", doc_type="test-type", id=42, body={"any": "data", "timestamp": datetime.now()})
Out[4]:
In [5]:
doc = {
'author': 'kimchy',
"email": "john@smith.com",
"first_name": "John",
"last_name": "Smith",
"info": {
"bio": "Eco-warrior and defender of the weak",
"age": 25,
"interests": [ "dolphins", "whales" ]
},
"join_date": "2014/05/01",
"timestamp": datetime.now()
}
In [6]:
res = es.index(index="test-index", doc_type='goo', id=1, body=doc)
print(res['created'])
In [7]:
res = es.get(index="test-index", doc_type='goo', id=1)
print(res['_source'])
In [8]:
res = es.search(index="test-index", body={"query": {"match_all": {}}})
print("Got %d Hits:" % res['hits']['total'])
In [20]:
for hit in res['hits']['hits']:
print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])
In [ ]: