ELK
엘라스틱서치 데이터 입력 조회 삭제 (GET, POST, PUT, DELETE)
✨✨✨✨✨✨✨
2021. 5. 2. 20:49
반응형
섹션 2. 엘라스틱서치 (ElasticSearch)
엘라스틱서치 데이터 입력 조회 삭제 (GET, POST, PUT, DELETE)

0. 개념
Elastic Search |
RDBMS | CRUD |
---|---|---|
GET | SELECT | READ |
POST | INSERT | CREATE |
PUT | UPDATE | UPDATE |
DELETE | DELETE | DELETE |
1. classes 라는 Index 조회
요청1
curl -X GET "localhost:9200/classes?pretty"
결과1
{
"error" : "IndexMissingException[[classes] missing]",
"status" : 404
}
- ?pretty 응답 JSON DATA가 정리되어 표시된다.
2. classes Index 생성하기
요청2
curl -X PUT "localhost:9200/classes"
결과2
{
"acknowledged":true
}
classes 조회 요청
curl -X GET "localhost:9200/classes?pretty"
classes 조회 결과
{
"classes" : {
"aliases" : { },
"mappings" : { },
"settings" : {
"index" : {
"creation_date" : "1619953042122",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"version" : {
"created" : "1070699"
},
"uuid" : "TtCzaNfCTteXbkFzawK_kg"
}
},
"warmers" : { }
}
}
3. classes index 지우기
index 지우기 요청
curl -X DELETE "localhost:9200/classes?pretty"
index 지우기 결과
{
"acknowledged" : true
}
4. 아래 내용 생성하기
index | type | id |
---|---|---|
classes | class | 1 |
id란? RDBMS의 PK같은 것
ElasticSearch는 Restful API를 통해
index에 document를 추가한다 (= 문서를 색인화)
문서를 색인화 하기위해서는
index의 Type과 _id를 지정해주어야 한다.
- 요청 명령어 설명
요청
curl -X POST "localhost:9200/classes/class/1/?pretty" -d
'{"title" : "Algorithm", "professor": "John"}'
결과
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 1,
"created" : true
}
5. document 파일로 생성하기
- 파일명 : @oneclass.json
생성 실행
curl -X POST "localhost:9200/classes/class/1/?pretty" -d @oneclass.json
'{
"title" : "Machine Learning",
"Professor" : "Minsuk Heo",
"major" : "Computer Science",
"semester" : [
"spring",
"fall"
],
"student_count" : 100,
"unit" : 3,
"rating" : 5
}'
생성 결과
{
"_index" : "classes",
"_type" : "class",
"_id" : "1",
"_version" : 5,
"created" : true
}
반응형