Document 만들기

MiniDeveloper·2022년 1월 21일
0

Elasticsearch

목록 보기
3/7

도큐먼트 바로 만들기

-d 뒤에 자세한 옵션을 적을 수 있다.
(작은 따옴표를 닫기 전에는 엔터를 입력해도 된다.)
아래의 경우 과목명을 알고리즘으로 교수를 존으로 넣겠다는 내용을 json형식(인터넷 요청 양식으로) 입력하는 것

curl -XPUT -H "Content-Type: application/json" http://localhost:9200/classes/class/1/ -d '{"title" : "Algorithm", "professor" : "John"}'
Curl 옵션: REST API 사용할때 알아두면 유용.
  • -i: 응답 헤더 출력(옵션이 없으면 응답 본문만 출력)
  • -v: 중간 처리 과정, 오류 메세지, 요청 메세지와 응답 메세지를 헤더와 본문을 포함해 전체 출력
  • -X: 요청 메소드를 지정(옵션이 없으면 기본값은 GET)
  • -H: 요청 헤더를 지정
  • -d: 요청 본문을 지정(옵션이 없으면 본문이 없다)

Point: elasticsearch 6.0 버전 부터는 본문이 있는 요청의 경우 헤더를 application/json으로 지원
(관련 옵션: -H "Content-Type: application/json")

아래처럼 successful 뜨면 완료

이제 올린 Index 확인 해보기

curl -XGET http://localhost:9200/classes/class/1

파일로 Document 만들기

json파일이 있는 경로로 이동.

oneclass.json 파일 내용 확인

less oneclass.json

이 파일로 도큐먼트 만들기

curl -XPOST -H "Content-Type: application/json" http://localhost:9200/classes/class/1/ -d @oneclass.json

이제 생성한 index 확인하기

curl -XGET http://localhost:9200/classes/class/1

profile
미니 개발자의 개발 일기

0개의 댓글