DB

[Elasticsearch] 설치 및 Index, Document 생성

Karla Ko 2023. 8. 29. 01:13
728x90

1. 설치

1.접속하여 다운로드

https://www.elastic.co/kr/downloads/past-releases#elasticsearch

 

Past Releases of Elastic Stack Software

Looking for a past release of Elasticsearch, Logstash, Kibana, es-hadoop, Shield, Marvel, or our language clients? You're in the right place.

www.elastic.co

 

2. 다운로드 경로에서 실행

cd elasticsearch-8.9.1
./bin/elasticsearch

 

3. 접속

curl -XGET http://localhost:9200

 

[에러] Received plaintext http traffic on an https channel, closing connection

https의 ssl 인증서에 대한 보안적인 이슈 문제, elasticsearch.yml 파일의 옵션 false로 지정하여 테스트 진행

vi ./config/elasticsearch.yml

 

4. 정상 실행

 

2. Document

ElasticSearch 저장 구조에는 Index, Document, Field, Mapping 가 있습니다.
Index → Database
Document → row
Field → column
Mapping → schema

 

1. document 생성

curl -XPOST http://[Elasticsearch Server IP]:9200/[INDEX NAME]/[ID]
-H 'Content-Type: application/json' -d '[JSON DATA]'
curl -XPUT http://localhost:9200/item/_doc/1 -H 'Content-Type: application/json' -d'
{
  "title": "테스트 제목",
  "message": "안녕하세요 Elasticsearch"
}'

Document는 Index와 Type이 생성되어 있지 않더라도 Document를 추가하는 시점에 지정한 Index와 Type이 생성할 수 있습니다.

 

2 document 조회

curl -XGET http://[Elasticsearch Server IP]:9200/[INDEX NAME]/_search
curl -X GET http://localhost:9200/item/_search\?pretty

 

 

 

 

728x90