오픈소스/ELK stack

[ElasticSearch] 데이터 처리

닝닝깅 2021. 6. 30. 17:54

GET (인덱스 확인)

$ curl -XGET [elasticsearch주소] [Index이름] (?pretty)

 

PUT (인덱스 생성)

$ curl -XPUT [elasticsearch주소] [Index이름]

 

POST (document 생성)

$ curl -XPOST [elasticsearch주소] [Index이름] [type명] [id] [Content-type] -d '

파일을 직접 올릴 경우 @파일명 추가

 

예) curl -XPOST http://localhost:9200/classes/class/1/ -H'Content-Type: application/json' -d '

 

DELETE (인덱스 삭제)

$ curl -XDELETE [elasticsearch주소] [Index이름]

 

 

데이터 업데이트

$ curl -XPOST [elasticsearch주소] [Index이름] [type명] [id]_update (?pretty) -d '

> {"doc" : {"unit" : 2}} '  ==> doc 값이 2로 수정

> {"script" : "ctx._source.unit += 5"} ' ==> doc값이 기존값에서 2더해진 값으로 수정

 

 

Bulk

여러개의 document를 한번에 elasticsearch에 삽입한다

 

Search

$ curl -XGET localhost:9200/basketball/record/_search?pretty

 

Query의 points가 30인 것만 나타내기

방법 1. URI옵션

$ curl -XGET 'localhost:9200/basketball/record/_search?q=points:30&pretty'

 

방법 2. Request body

curl -XGET 'localhost:9200/basketball/record/_search -d'
{
	"query":{
    	"term": {"points":30}
    }
}'