Skip to content

Commit

Permalink
Add kibana and python examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rtancman committed Oct 27, 2020
1 parent d4ab964 commit e64811c
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 0 deletions.
41 changes: 41 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: '2.2'
services:
es:
image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0
container_name: es
environment:
- node.name=es
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es
- cluster.initial_master_nodes=es
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- es_data:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- elastic

kibana:
image: docker.elastic.co/kibana/kibana:7.9.0
container_name: kibana
ports:
- 5601:5601
environment:
ELASTICSEARCH_URL: http://es:9200
ELASTICSEARCH_HOSTS: http://es:9200
networks:
- elastic

volumes:
es_data:
driver: local

networks:
elastic:
driver: bridge
5 changes: 5 additions & 0 deletions kibana/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# elasticsearch-sandbox kibana


Vamos utilizar o kibana para rodar todos os comandos de criação de indices, para criar os documentos e buscar os mesmos.

3 changes: 3 additions & 0 deletions kibana/example1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# elasticsearch-sandbox kibana example 1

Vamos seguir os passos do artigo https://www.rtancman.com.br/information-retrieval/elasticsearch-como-ferramenta-de-busca.html#executando-comandos-do-elasticsearch
76 changes: 76 additions & 0 deletions kibana/example2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# elasticsearch-sandbox kibana example 2

Vamos ver na prática como os analyzers e os tokenizers funcionam.

```
PUT /example2
{
"settings": {
"index": {
"analysis": {
"filter": {
"synonym": {
"type": "synonym",
"lenient": true,
"synonyms": [
"i-pod, i pod => ipod",
"universe, cosmos"
]
}
},
"analyzer": {
"default": {
"filter": [
"asciifolding",
"lowercase",
"stop",
"synonym"
],
"tokenizer": "standard"
}
}
}
}
}
}
GET /_analyze
{
"tokenizer": "standard",
"filter": [ "stop" ],
"text": "a quick fox jumps over the lazy dog"
}
POST /example2/_analyze
{
"analyzer": "default",
"text": "Este é um exemplo de texto que eu gostaria de indexar."
}
POST /example2/_analyze
{
"analyzer": "default",
"text": "i pod e cosmos são coisas bem loucas!"
}
POST /example2/_doc
{
"title":"Este é um exemplo de texto que eu gostaria de indexar."
}
POST /example2/_doc
{
"title":"exemplo para comprar um i pod."
}
GET /example2/_search
{
"query": {
"query_string": {
"query":"exemplo de texto",
"analyzer": "default"
}
}
}
```
7 changes: 7 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# elasticsearch-sandbox python


Vamos utilizar o cliente python oficial do elasticsearch que é o [elastic/elasticsearch-py](https://github.com/elastic/elasticsearch-py).

O link da documentação é o [https://elasticsearch-py.readthedocs.io/en/master/index.html](https://elasticsearch-py.readthedocs.io/en/master/index.html).

21 changes: 21 additions & 0 deletions python/example1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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"])
Empty file added python/example2.py
Empty file.

0 comments on commit e64811c

Please sign in to comment.