How to install and use python Elasticsearch

Installation

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.',
    'timestamp': datetime.now(),
}
res = es.index(index="test-index", doc_type='tweet', id=1, body=doc)
print(res['result'])

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

 

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.