Skip to content

Commit 4e0dbd0

Browse files
committed
Add python example 1
1 parent ea9d2b1 commit 4e0dbd0

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

python/example1.py

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,76 @@
1818
res = es.search(index="test-index", body={"query": {"match_all": {}}})
1919
print("Got %d Hits:" % res['hits']['total']['value'])
2020
for hit in res['hits']['hits']:
21-
print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])
21+
print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])
22+
23+
resp = es.search(
24+
index="test-index",
25+
size=0,
26+
body={
27+
"query": {
28+
"query_string": {
29+
"query":"bonsai"
30+
}
31+
}
32+
}
33+
)
34+
35+
print(resp)
36+
37+
38+
39+
## criando indices
40+
41+
es.indices.create(
42+
index="filmes-python",
43+
body={
44+
"settings": {"number_of_shards": 1},
45+
"mappings": {
46+
"properties": {
47+
"nome": {
48+
"type": "text"
49+
},
50+
"descricao": {
51+
"type": "text"
52+
},
53+
"nota": {
54+
"type": "float"
55+
},
56+
"classificao": {
57+
"type": "text"
58+
},
59+
"data_lancamento": {
60+
"type": "date"
61+
}
62+
}
63+
},
64+
},
65+
ignore=400,
66+
)
67+
68+
69+
doc_id = '7Rt9cXUBhWsOrFfCWDh1'
70+
doc = {
71+
"nome": "Matrix",
72+
"descricao": "Melhor filme ever!",
73+
"classificao": "livre",
74+
"nota": 10,
75+
"data_lancamento": "1999-05-21T14:12:12"
76+
}
77+
## criar o documento
78+
res = es.index(index="filmes-python", id=doc_id, body=doc)
79+
print(res)
80+
81+
## pegar documentos
82+
res = es.get(index='filmes-python',id=doc_id)
83+
print(res)
84+
85+
86+
## deletar
87+
88+
res = es.delete(index='filmes-python',id=doc_id)
89+
print(res['result'])
90+
91+
92+
## busca
93+
res= es.search(index='filmes-python',body={'query':{'match_all':{}}})

0 commit comments

Comments
 (0)