How to install and use python Elasticsearch


Install the elasticsearch package with pip:

pip install elasticsearc

Example Usage

from datetime import datetime
from elasticsearch import Elasticsearch
es = Elasticsearch()

doc = {
    'author': 'kimchy',
    'text': 'Elasticsearch: cool. bonsai cool.',
res = es.index(index="test-index", doc_type='tweet', id=1, body=doc)

res = es.get(index="test-index", doc_type='tweet', id=1)


res ="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"])


Where should we young people go in the future?

It’s very fast that my age is nearly to 30.  I feel very anxious. Because many dreams have not yet been realized. For example that cars and house. The most import thing is that I can’t afford to spend money to buy what I want.

I save money every day,but the money is depreciating. What’s the right direction way I shoud go? Who can tell me?

Fortunately, I have a lovely wife who love me.