https://github.com/sensorario/docker-elasticsearch
https://github.com/sensorario/docker-elasticsearch
dev-romagna docker elasticsearch
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/sensorario/docker-elasticsearch
- Owner: sensorario
- Created: 2018-05-30T04:51:44.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-01-25T10:21:49.000Z (over 4 years ago)
- Last Synced: 2025-04-05T02:41:44.617Z (about 1 year ago)
- Topics: dev-romagna, docker, elasticsearch
- Language: Makefile
- Size: 12.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Elasticsearch
## Introduction
ES provides a REST interface to read and write data. In this repository I'll
list a couple of snippet or information to start to play with ES.
## Install with docker
We'll use ES inside a docker machine.
First of all pull docker image:
```
> docker pull docker.elastic.co/elasticsearch/elasticsearch:6.2.4
```
Second, run docker:
```
> docker run -p 9300:9300 -p 9200:9200 docker.elastic.co/elasticsearch/elasticsearch:6.2.4
```
Now start with CRUD operations
## Create new index and properties mapping.
### Request
An index is created just adding a resource.
```
> PUT http://localhost:9200/indice
> {
> "mappings": {
> : {
> "properties": {
> : {
> "type":
> }
> }
> }
> }
> }
```
### Response
```
< {
< "acknowledged": true,
< "shards_acknowledged": true,
< "index": "indice"
< }
```
## See indexes in browser
### Request
```
> http://localhost:9200/_cat/indices
```
### Response
yellow open indice Fly0K1RcSRumG86Xr-VYXQ 5 1 0 0 1.1kb 1.1kb
green open .monitoring-es-6-2018.05.29 rtrWxymcRe-p9SogkIC32w 1 0 318 55 392.3kb 392.3kb
## Create new record
### Request
```
> PUT http://localhost:9200/indice/_doc/1
> {
> "ip_addr": "192.168.1.1"
> }
```
### Response
```
< {
< "_index": "indice",
< "_type": "_doc",
< "_id": "1",
< "_version": 1,
< "result": "created",
< "_shards": {
< "total": 2,
< "successful": 1,
< "failed": 0
< },
< "_seq_no": 0,
< "_primary_term": 1
< }
```
## Get record
### Request
```
> GET http://localhost:9200/indice/_doc/2
```
### Response
```
< {
< "_index": "indice",
< "_type": "_doc",
< "_id": "2",
< "_version": 6,
< "found": true,
< "_source": {
< "ip_addr": "192.168.1.2"
< }
< }
```
## Search inside index
### Request
```
> Content-type: application/json
> GET http://localhost:9200/indice/_search/
> {
> "query": {
> "term": {
> "ip_addr":"192.168.2.2/16"
> }
> }
> }
```
### Response
```
< {
< "took" : 3,
< "timed_out" : false,
< "hits" : {
< "total" : 1,
< "max_score" : 1,
< "hits" : [
< {
< "_score" : 1,
< "_source" : {
< "ip_addr" : "192.168.2.2"
< },
< "_type" : "_doc",
< "_id" : "2",
< "_index" : "indice"
< }
< ]
< },
< "_shards" : {
< "failed" : 0,
< "total" : 5,
< "successful" : 5,
< "skipped" : 0
< }
< }
```
## Multiple search
### Request
```
> GET index/type/_search
> {
> "query": {
> "bool": {
> "must": [
> {
> "match": {
> "path.to.some.field.keyword": "value"
> }
> },
> {
> "match": {
> "path.to.another.field.keyword": "another value"
> }
> }
> ]
> }
> }
> }
```
## Pagination
### Limit and offset
```
> GET index/type/_search?size=10
> GET index/type/_search?size=10&from=42
```