IT하는 참새
04. Elastic Search 명령어 본문
Elastic Search는 Restful API를 지원한다고 했다
HTTP프로토콜을 통해 통신한다는 것이므로
GET, POST, PUT, DELETE ... 메소드를 사용한다는 것임!!
이번에는 해당 메소드들을 사용해보겠다
(Elastic Search기본포트는 9200)
먼저
GET (조회)
curl -XGET 'Elastic Search주소'
예시)
curl -XGET 'http://localhost:9200'
그냥 Elastic Search에 접속(실행)한 것이다. 여러 정보가 나온다 (결과도 JSON이군!!)
PUT (인덱스에 사용되는 삽입)
curl -XPUT 'Elastic Search주소/index이름'
예시)
curl -XPUT 'http://localhost:9200/school'
명령어 실행했더니 JSON형태로 acknowledged, index등 여러 정보가 나왔다
그런데 영 보기 불편함.......
그래서!!! url뒤에 get방식으로 ?pretty를 붙여주면 결과가 예쁘게 나온다
(앞으로 모든 명령어 실행 후 이렇게 pretty를 붙여주면 결과가 예쁘게 나옴)
(GET, PUT, POST, DELETE 모두)
POST (Type에 사용되는 삽입)
(doc이름 없으면 생성해줌)
curl -XPOST 'Elastic Search주소/index이름/doc이름' (추가옵션들)
예시)
(doc생성과 동시에 데이터 저장)
curl -XPOST 'http://localhost:9200/school/student/1' -H 'Content-Type : application/json' -d '{"name" : "son", "age" : 13}'
(Elastic Search 6.x 버전부터 POST시에 -H 'Content-Type : application/json' 필수)
(-d뒤에는 json형식으로 데이터를 집어넣는것임)
(/school/student/1 에서 1은 student type(테이블)에 document(row)지정하는 것임)
(doc생성과 동시에 데이터 저장 - 데이터를 json파일에서 불러오기)
curl -XPOST 'http://localhost:9200/school/student/1' -H 'Content-Type : application/json' -d @test.json
DELETE (인덱스 삭제, Document삭제)
curl -XDELETE 'Elastic Search주소/index이름/doc이름/{id}'
예시)
Document삭제 (방금전 POST로 추가한 id가 3인 Document를 삭제하기)
curl -XDELETE 'http://localhost:9200/school/student/3?pretty'
(result보면 deleted. 잘 지워졌다!!)
Index삭제 (student db삭제임)
(잘 지워졌단다)
실제로 확인해볼까??
(조회를 해서 결과가 나오면 존재하고, 안나오면 존재하지 않겠네)
curl -XGET 'http://localhost:9200/school?pretty'
index찾을수 없다고 나옴
잘 삭제됐나보다!!!!
이렇게 기본적인 메소드들을 공부했음
'빅데이터 > ELK Stack' 카테고리의 다른 글
03. Elastic Search 개념정리 (0) | 2018.08.06 |
---|---|
02. Elastic Search 설치 (0) | 2018.08.06 |
01. ELK란? (0) | 2018.08.06 |