Answers for "elasticsearch"

2

python elasticsearch

# to install 
python -m 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", id=1, body=doc)
print(res['result'])

res = es.get(index="test-index", 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']['value'])
for hit in res['hits']['hits']:
    print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])
Posted by: Guest on March-05-2021
0

install elasticsearch

sudo apt-get update
sudo apt-get -y install elasticsearch
sudo systemctl start elasticsearch
sudo systemctl enable elasticsearch
Posted by: Guest on October-20-2020

Python Answers by Framework

Browse Popular Code Answers by Language