Skip to content

Commit e64811c

Browse files
committed
Add kibana and python examples
1 parent d4ab964 commit e64811c

File tree

7 files changed

+153
-0
lines changed

7 files changed

+153
-0
lines changed

docker-compose.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
version: '2.2'
2+
services:
3+
es:
4+
image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0
5+
container_name: es
6+
environment:
7+
- node.name=es
8+
- cluster.name=es-docker-cluster
9+
- discovery.seed_hosts=es
10+
- cluster.initial_master_nodes=es
11+
- bootstrap.memory_lock=true
12+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
13+
ulimits:
14+
memlock:
15+
soft: -1
16+
hard: -1
17+
volumes:
18+
- es_data:/usr/share/elasticsearch/data
19+
ports:
20+
- 9200:9200
21+
networks:
22+
- elastic
23+
24+
kibana:
25+
image: docker.elastic.co/kibana/kibana:7.9.0
26+
container_name: kibana
27+
ports:
28+
- 5601:5601
29+
environment:
30+
ELASTICSEARCH_URL: http://es:9200
31+
ELASTICSEARCH_HOSTS: http://es:9200
32+
networks:
33+
- elastic
34+
35+
volumes:
36+
es_data:
37+
driver: local
38+
39+
networks:
40+
elastic:
41+
driver: bridge

kibana/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# elasticsearch-sandbox kibana
2+
3+
4+
Vamos utilizar o kibana para rodar todos os comandos de criação de indices, para criar os documentos e buscar os mesmos.
5+

kibana/example1.md

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

kibana/example2.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# elasticsearch-sandbox kibana example 2
2+
3+
Vamos ver na prática como os analyzers e os tokenizers funcionam.
4+
5+
```
6+
PUT /example2
7+
{
8+
"settings": {
9+
"index": {
10+
"analysis": {
11+
"filter": {
12+
"synonym": {
13+
"type": "synonym",
14+
"lenient": true,
15+
"synonyms": [
16+
"i-pod, i pod => ipod",
17+
"universe, cosmos"
18+
]
19+
}
20+
},
21+
"analyzer": {
22+
"default": {
23+
"filter": [
24+
"asciifolding",
25+
"lowercase",
26+
"stop",
27+
"synonym"
28+
],
29+
"tokenizer": "standard"
30+
}
31+
}
32+
}
33+
}
34+
}
35+
}
36+
37+
GET /_analyze
38+
{
39+
"tokenizer": "standard",
40+
"filter": [ "stop" ],
41+
"text": "a quick fox jumps over the lazy dog"
42+
}
43+
44+
POST /example2/_analyze
45+
{
46+
"analyzer": "default",
47+
"text": "Este é um exemplo de texto que eu gostaria de indexar."
48+
}
49+
50+
POST /example2/_analyze
51+
{
52+
"analyzer": "default",
53+
"text": "i pod e cosmos são coisas bem loucas!"
54+
}
55+
56+
57+
POST /example2/_doc
58+
{
59+
"title":"Este é um exemplo de texto que eu gostaria de indexar."
60+
}
61+
62+
POST /example2/_doc
63+
{
64+
"title":"exemplo para comprar um i pod."
65+
}
66+
67+
GET /example2/_search
68+
{
69+
"query": {
70+
"query_string": {
71+
"query":"exemplo de texto",
72+
"analyzer": "default"
73+
}
74+
}
75+
}
76+
```

python/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# elasticsearch-sandbox python
2+
3+
4+
Vamos utilizar o cliente python oficial do elasticsearch que é o [elastic/elasticsearch-py](https://github.com/elastic/elasticsearch-py).
5+
6+
O link da documentação é o [https://elasticsearch-py.readthedocs.io/en/master/index.html](https://elasticsearch-py.readthedocs.io/en/master/index.html).
7+

python/example1.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from datetime import datetime
2+
from elasticsearch import Elasticsearch
3+
es = Elasticsearch()
4+
5+
doc = {
6+
'author': 'kimchy',
7+
'text': 'Elasticsearch: cool. bonsai cool.',
8+
'timestamp': datetime.now(),
9+
}
10+
res = es.index(index="test-index", id=1, body=doc)
11+
print(res['result'])
12+
13+
res = es.get(index="test-index", id=1)
14+
print(res['_source'])
15+
16+
es.indices.refresh(index="test-index")
17+
18+
res = es.search(index="test-index", body={"query": {"match_all": {}}})
19+
print("Got %d Hits:" % res['hits']['total']['value'])
20+
for hit in res['hits']['hits']:
21+
print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])

python/example2.py

Whitespace-only changes.

0 commit comments

Comments
 (0)