Mudanças entre as edições de "Python:ElasticSearch"
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 = { '...') |
|||
| Linha 1: | Linha 1: | ||
= Python:Extraindo informações URL = | = Python:Extraindo informações URL = | ||
pip install elasticsearch | pip install elasticsearch | ||
| + | |||
| + | == Conectando com o ElasticSearch == | ||
| + | from datetime import datetime | ||
| + | from elasticsearch import Elasticsearch | ||
| + | class elasticsearch: | ||
| + | def __init__(self) -> None: | ||
| + | self.elasticsearch_url = 'http://143.54.112.91:9200' | ||
| + | def connect(self): | ||
| + | es = Elasticsearch(self.elasticsearch_url) | ||
| + | print(es.info()) | ||
| + | es = Elasticsearch(self.elasticsearch_url) | ||
| + | print(es.info()) | ||
| + | |||
| + | == Indexando um documento == | ||
from datetime import datetime | from datetime import datetime | ||
Edição atual tal como às 22h18min de 22 de janeiro de 2023
Python:Extraindo informações URL
pip install elasticsearch
Conectando com o ElasticSearch
from datetime import datetime
from elasticsearch import Elasticsearch
class elasticsearch:
def __init__(self) -> None:
self.elasticsearch_url = 'http://143.54.112.91:9200'
def connect(self):
es = Elasticsearch(self.elasticsearch_url)
print(es.info())
es = Elasticsearch(self.elasticsearch_url)
print(es.info())
Indexando um documento
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"])