반응형

[ELK] Elasticsearch


작성일자 : 2019년 01월 28일


1. Elasticsearch란?


Elasticsearch는 Elastic에서 제공하는 확장성이 뛰어난 오픈 소스 텍스트 검색 및 분석 엔진입니다. 대량의 데이터를 신속하고 거의 실시간으로 저장, 검색 및 분석 할 수 있습니다. 일반적으로 복잡한 검색 기능과 요구 사항이 있는 응용 프로그램을 구동하는 기본 엔진 / 기술로 사용됩니다.



2. 기본 개념


DB와 컨셉은 유사하고 DB와 비교하여 이해하면 이해하기 용이하다.


ElasticSearch 

DB 

Index

Database 

Type 

Table 

Document 

Row 

Field 

Column 

Mapping 

Schema 


다만 저장 방식은 DB와 차이를 보인다.

RDB의 경우 document=Item로 저장되어, 특정 Item을 검색하기 위해서는 모든 document를 조회하며 조건에 맞는 Item을 검색하는 반면,

Elasticsearch의 경우 Item=document의 방식으로 저장되어, 특정 Item을 가지는 document가 이미 저장 되어있어 검색시 매우 빠른 속도를 가진다. 

 

또한 Elasticsearch는 REST API를 기본으로 동작한다.



3. 설치 및 실행


환경 : Windows 7, Elasticsearch 6.5.4, JDK 1.8


3.1 설치파일 다운로드 


https://www.elastic.co/downloads/elasticsearch




3.2 알집 해제




3.3 elasticsearch.bat 실행




started 문구가 보이면 실행 성공!


3.4 확인


브라우저 접속 후 localhost:9200 접근 ( Elasticsearch Default port : 9200 )


4. 기본 동작


curl을 사용하여 CRUD 기본동작을 검증 ( Window에선 curl 사용을 위해선 추가 설치가 필요하며 본 과정에서는 Git Bash를 활용 )


  • Create (==Insert)


-XPOST localhost:9200/index/type/document -d "{"Item":"test"}" -H 'Content-Type: application/json'

( == INSERT INTO type (Item) VALUES ("test"); ) 

 


id가 "document"인 document에 { Item=test } JSON 형태의 값을 삽입 


  • Read (==Select)

-XGET localhost:9200/index/type/document

( == SELECT * FROM type WHERE id = "document"; ) 



id가 "document"인 document를 검색 -> Item=test 데이터 조회 성공


  • Update

-XPUT localhost:9200/index/type/document -d "{"Item":"ModTest"}" -H 'Content-Type: application/json'

( == UPDATE type set Item="ModTest" WHERE id = "document"; )



id가 "document"인 document의 Item의 값을 "ModTest"로 수정



  • Read (==Select)

-XGET localhost:9200/index/type/document

( == SELECT * FROM type WHERE id = "document"; ) 



id가 "document"인 document를 검색 -> Item=ModTest 수정된 데이터 조회 성공


  • Delete

-XDELETE localhost:9200/index/type/document

( == DELETE from type WHERE id="document"; ) 



id가 "document"인 document를 삭제 


  • Read (==Select)

-XGET localhost:9200/index/type/document

( == SELECT * FROM type WHERE id = "document"; ) 



id가 "document"인 document를 검색 -> 삭제 된 데이터의 조회 실패 ( 삭제 성공 )

반응형

'도구, 툴' 카테고리의 다른 글

[ELK] Kibana  (1) 2019.01.29
[ELK] Logstash  (0) 2019.01.28
[ELK] ELK 개요  (0) 2019.01.23
R 설치  (0) 2019.01.07
SVN 권한 설정  (1) 2018.02.10

+ Recent posts