2021년 1월 6일 수요일

[elk] csv 파일 logstash 를 이용하여 엘라스틱 인덱싱하기

[elk] csv 파일 logstash 를 이용하여 엘라스틱 업로드하기

csv 파일 logstash 를 이용하여 elasticsearch 에 인덱싱 하기

https://github.com/pranav-shukla/learningelasticstack/tree/master/chapter-03 내용을 참조 하였고 elk 버전은 7.10 이다

http://dbs.uni-leipzig.de/file/Amazon-GoogleProducts.zip zip 파일 다운로드

  1. /usr/share/logstash 에 files 디렉토리 생성후 다운 받은 zip 파일의 압축을풀고 Amazon.csv 파일을 products.csv 로 이름을 변경 하여 /usr/share/logstash/files 디렉토리에 위치 시킨다.

  2. 같은 위치에 아래 내용을 복사하여 logstash_products.conf 파일로 저장한다. 1번에서 생성한 products.csv 파일와 path 경로가 일치해야되며 elasticsearch 계정이 있는경우는 output > elasticsearch 밑에 user => “계정”
    password => “패스워드” 를 설정해주어야 한다.

input {
 file {
   path => "/usr/share/logstash/files/products.csv"
   start_position => "beginning"
   sincedb_path => "/dev/null"
   codec => plain {
     charset => "ISO-8859-1"
   }
 }
}
filter {
 csv {
   separator => ","
   columns => ["id","title","description","manufacturer","price"]
 }

 mutate {
   remove_field => ["@version","@timestamp","path","host", "tags", "message"]
 }
}
output {
 elasticsearch {
   hosts => "http://localhost:9200"
   index => "amazon_products"
 }
 stdout {}
}
  1. kibana 의 DEVTOOL 에서 인덱스를 생성한다.
PUT /amazon_products
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0,
    "analysis": {
      "analyzer": {}
    }
  },
  "mappings": {
    "properties": {
      "id": {
        "type": "keyword"
      },
      "title": {
        "type": "text"
      },
      "description": {
        "type": "text"
      },
      "manufacturer": {
        "type": "text",
        "fields": {
          "raw": {
            "type": "keyword"
          }
        }
      },
      "price": {
        "type": "scaled_float",
        "scaling_factor": 100
      }
    }
  }
}
  1. logstash 를 실행하여 csv 파일 데이터를 elasticsearch 에 인덱싱 한다.
cd /usr/share/logstash
bin/logstash -f files/logstash_products.conf
  1. kibana DEVTOOL 에서 데이터를 확인한다.
GET /amazon_products/_search
{
  "query": {
    "match_all": {}
  }
}

검색된 데이터가 확인된다면 정상

{
  "took" : 910,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1363,
      "relation" : "eq"
    },
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "amazon_products",
        "_type" : "_doc",
        "_id" : "HFbK2nYB-Q87Y8iF9T-L",
        "_score" : 1.0,
        "_source" : {
          "id" : "b000gzwjgc",
          "manufacturer" : "nuance academic",
          "title" : "acad upgrade dragon naturallyspeaking pro solution 9.0 (a289a-fd7-9.0)",
          "description" : "- marketing information: dragon naturallyspeakingprofessional 9 will saveyou and your

댓글 없음:

댓글 쓰기

[lunux]리눅스 폴더별 용량 확인

리눅스 폴더별 용량 확인 조회 하고자 하는 디렉토리 리스트가있는 경로로 이동후 du -h --max-depth=1