|
1 | 1 | # elasticsearch-sandbox kibana example 1
|
2 | 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 |
| 3 | +Vamos seguir os passos do artigo https://www.rtancman.com.br/information-retrieval/elasticsearch-como-ferramenta-de-busca.html#executando-comandos-do-elasticsearch |
| 4 | + |
| 5 | + |
| 6 | +### Executando comandos do elasticsearch |
| 7 | + |
| 8 | +``` |
| 9 | +
|
| 10 | +GET /_cat/indices |
| 11 | +
|
| 12 | +PUT /meu_primeiro_index |
| 13 | +
|
| 14 | +
|
| 15 | +``` |
| 16 | + |
| 17 | + |
| 18 | +### Criando um indice |
| 19 | + |
| 20 | +``` |
| 21 | +PUT /filmes |
| 22 | +{ |
| 23 | + "mappings": { |
| 24 | + "properties": { |
| 25 | + "nome": { |
| 26 | + "type": "text" |
| 27 | + }, |
| 28 | + "descricao": { |
| 29 | + "type": "text" |
| 30 | + }, |
| 31 | + "nota": { |
| 32 | + "type": "float" |
| 33 | + }, |
| 34 | + "classificao": { |
| 35 | + "type": "text" |
| 36 | + }, |
| 37 | + "data_lancamento": { |
| 38 | + "type": "date" |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | +
|
| 44 | +GET /filmes/_mapping |
| 45 | +GET /filmes/_settings |
| 46 | +``` |
| 47 | + |
| 48 | + |
| 49 | +### Criando documentos |
| 50 | + |
| 51 | +``` |
| 52 | +POST /filmes/_doc/ |
| 53 | +{ |
| 54 | + "nome": "Matrix", |
| 55 | + "descricao": "Melhor filme ever!", |
| 56 | + "classificao": "livre", |
| 57 | + "nota": 10, |
| 58 | + "data_lancamento": "1999-05-21T14:12:12" |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +### Editando documentos |
| 63 | + |
| 64 | +``` |
| 65 | +POST filmes/_update/ID_DO_DOC |
| 66 | +{ |
| 67 | + "doc": { |
| 68 | + "classificao": "Não recomendado para menores de doze anos" |
| 69 | + } |
| 70 | +} |
| 71 | +
|
| 72 | +``` |
| 73 | + |
| 74 | +### Lendo documentos |
| 75 | + |
| 76 | +``` |
| 77 | +
|
| 78 | +GET filmes/_doc/-DEY_XIBblRt4Ct0995B |
| 79 | +
|
| 80 | +``` |
| 81 | + |
| 82 | +### Removendo documentos |
| 83 | + |
| 84 | +``` |
| 85 | +
|
| 86 | +DELETE filmes/_doc/-DEY_XIBblRt4Ct0995B |
| 87 | +
|
| 88 | +``` |
| 89 | + |
| 90 | + |
| 91 | +### Criando varios documentos |
| 92 | + |
| 93 | +``` |
| 94 | +
|
| 95 | +POST /filmes/_bulk |
| 96 | +{"index":{}} |
| 97 | +{"nome":"Matrix","descricao":"Melhor filme ever!","classificao":"Não recomendado para menores de doze anos","nota":10,"data_lancamento":"1999-05-21T14:12:12"} |
| 98 | +{"index":{}} |
| 99 | +{"nome":"Matrix Reloaded","descricao":"Melhor filme ever!!!!","classificao":"Não recomendado para menores de doze anos","nota":8.5,"data_lancamento":"2003-05-15T11:30:00"} |
| 100 | +{"index":{}} |
| 101 | +{"nome":"Matrix Revolutions","descricao":"Melhor filme ever!!!!","classificao":"Não recomendado para menores de doze anos","nota":8.9,"data_lancamento":"2003-11-05T11:30:00"} |
| 102 | +{"index":{}} |
| 103 | +{"nome":"Matrix 4","descricao":"Melhor filme ever!!!!","classificao":"Não recomendado para menores de doze anos","nota":0,"data_lancamento":"2022-04-01T11:30:00"} |
| 104 | +
|
| 105 | +
|
| 106 | +``` |
| 107 | + |
| 108 | + |
| 109 | +### Realizando queries |
| 110 | + |
| 111 | +``` |
| 112 | +GET /filmes/_search |
| 113 | +
|
| 114 | +GET filmes/_search |
| 115 | +{ |
| 116 | + "query": { |
| 117 | + "match": { |
| 118 | + "nome": "Matrix" |
| 119 | + } |
| 120 | + } |
| 121 | +} |
| 122 | +
|
| 123 | +GET filmes/_search |
| 124 | +{ |
| 125 | + "query": { |
| 126 | + "match": { |
| 127 | + "nome": "Matrix" |
| 128 | + } |
| 129 | + } |
| 130 | +} |
| 131 | +
|
| 132 | +
|
| 133 | +GET /filmes/_search |
| 134 | +{ |
| 135 | + "query": { |
| 136 | + "range": { |
| 137 | + "nota": { |
| 138 | + "gte": 2, |
| 139 | + "lte": 9 |
| 140 | + } |
| 141 | + } |
| 142 | + } |
| 143 | +} |
| 144 | +
|
| 145 | +
|
| 146 | +GET /filmes/_search |
| 147 | +{ |
| 148 | + "query": { |
| 149 | + "query_string": { |
| 150 | + "query":"Matrix" |
| 151 | + } |
| 152 | + } |
| 153 | +} |
| 154 | +
|
| 155 | +``` |
0 commit comments