1. Elasticsearch 용어




   1) index 


      - collection of different types of document  under on logical namespace 


        (rdb에서 schema와 같은 역할)


      - shard의 수 및 replica를 설정


      - multitenant 지원 하고 자유로이 생성 및 삭제가능




   2) type


      - logical collection of documents like the same entity


        (rdb에서 table와 같은 역할)


      - table과 같은 domain objects 표현 (client, company, user...)




   3) document


      - logical unit that represents the instance of an entity


        (rdb에서 row와 같은 역할)


      - json object




   4) field


      - multiple fields that are organized as JSON key / value pairs.


        (rdb에서 columns와 같은 역할)




출처: http://semode.tistory.com/30 [세모데]

운영체제 :  window7 





1. 모든 인덱스 조회


GET _search

{

  "query": {

    "match_all": {}

  }

}


2, AGE 값이 20 인 데이터 찾기

GET _search

{

  "query": { "match": { "age": "20" } }

}


2.1 원하는 인덱스에서 원하는 데이터 찾기

GET /blog1/_search

{

  "query": { "match": { "age": "20" } }

}


3. 신규 데이터 넣기
PUT /blog1/article/4
{
  
  "age":"1"
}


운영체제 :  window7 


1.Logstash다운로드 

> https://www.elastic.co/downloads/logstash





2.CONF 파일 생성


2-1   1. 에서 다운 받은 ZIP을 원하는 디렉토리에 압축 해제 하여 CONF 파일을 생성 하기전 아래와 같이 CMD 에서 실행 해본다

(바로 2-2로 가도 상관 없음.)

>> bin\logstash.bat -e 'input { stdin {} } output { stdout {} }'

 


2-2 CONF파일 생성 후 실행 


BIN 폴더와 같은 디렉토리에  아래와 같이 CONF 파일을 설정 한다



input {

        stdin {

                codec => json

        }

file {

            path => "B:/***/2017-09-18.log"   # 해당 위치의 파일이 변경 되면 엘라스틱 엔진에 데이터를 넣는다

          }

}


output {

        elasticsearch {

               # host => "localhost"

               index => "log"                      # LOG 인덱스가 없을 경우 생성 하여 해당 인덱스에 넣어준다   

               # index_type => "article"

               # protocol => "http"

      hosts => ["localhost:9200"]

        }

        stdout {

                codec => json { }

        }

file {

                path => "B:/STUDY/Java/logstash-5.6.0/logs/WebLog/webLog.log"

codec => json { }

        }


}


2-3 cmd 에서  bin\logstash.bat -f logstash.conf 때린다


오류없이 정상 처리 되면 성공



3.테스트 

3-1. B:/***/2017-09-18.log 파일을 열어 테스트 데이터를 넣어 정상적으로 넣어지는지 확인한다


{"document_srl":1, "subject":"first", "content":"first_content", "account":"first_acc", "reg_date":"2017-08-21"}

{"BOLLOG":1, "subject":"first", "content":"first_content", "account":"first_acc", "reg_date":"2017-08-21"}

{"BOLLOG":2, "subject":"first1", "content":"first_content", "account":"first_acc", "reg_date":"2017-08-21"}




3-2. 키바나에서 아래와 같이 넣어진 데이터를 확인 할 수 있다





해당 로그 파일데이터가 바뀔 때 마다 cmd에 로그가 찍힌다



3-3 넣은 데이터를 키바나 말고 웹브라우져 에서 확인 하기

>> http://localhost:9200/log/logs/AV6ZIqaHpVuiGdVMgWnQ








+ Recent posts