Mudanças entre as edições de "Python:ElasticSearch"

De BrapciWiki
Ir para navegação Ir para pesquisar
(Criou página com '= Python:Extraindo informações URL = pip install elasticsearch from datetime import datetime from elasticsearch import Elasticsearch es = Elasticsearch() doc = { '...')
(Sem diferença)

Edição das 21h55min de 22 de janeiro de 2023

Python:Extraindo informações URL

pip install elasticsearch
from datetime import datetime
from elasticsearch import Elasticsearch
es = Elasticsearch()
doc = {
   'author': 'kimchy',
   'text': 'Elasticsearch: cool. bonsai cool.',
   'timestamp': datetime.now(),
}
resp = es.index(index="test-index", id=1, document=doc)
print(resp['result'])
resp = es.get(index="test-index", id=1)
print(resp['_source'])
es.indices.refresh(index="test-index")
resp = es.search(index="test-index", query={"match_all": {}})
print("Got %d Hits:" % resp['hits']['total']['value'])
for hit in resp['hits']['hits']:
   print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])