File tree Expand file tree Collapse file tree 1 file changed +73
-1
lines changed Expand file tree Collapse file tree 1 file changed +73
-1
lines changed Original file line number Diff line number Diff line change 18
18
res = es .search (index = "test-index" , body = {"query" : {"match_all" : {}}})
19
19
print ("Got %d Hits:" % res ['hits' ]['total' ]['value' ])
20
20
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' :{}}})
You can’t perform that action at this time.
0 commit comments