Re: [문의] Dev tools를 사용한 데이터 업로드 방법 > 질문답변

본문 바로가기
사이트 내 전체검색

질문답변

Re: [문의] Dev tools를 사용한 데이터 업로드 방법

페이지 정보

profile_image
작성자 꿈꾸는여행자
댓글 0건 조회 10,804회 작성일 21-07-30 14:23

본문

안녕하세요.

Kibana UI의 Dev Tools를 사용할 것입니다.
Dev Tools는 Logstash를 사용하지 않고 Elasticsearch에서 데이터를 업로드하는 데 유용합니다.
Dev Tools를 사용하여 Kibana에서 원하는 데이터를 게시, 배치, 삭제, 검색할 수 있습니다.

Kibana 자체에서 샘플 데이터를 로드하려고 합니다. 이를 사용하여 샘플 데이터로 연습하고 Kibana 기능을 사용하여 Kibana를 잘 이해할 수 있습니다.
다음 URL에서 json 데이터를 가져와 Kibana에 업로드해 보겠습니다. 마찬가지로 Kibana 내부에 로드할 샘플 json 데이터를 시도할 수 있습니다.
샘플 데이터 업로드를 시작하기 전에 Elasticsearch에서 사용할 인덱스가 있는 json 데이터가 있어야 합니다. logstash를 사용하여 업로드할 때 logstash는 인덱스를 추가하는 데 주의를 기울이고 사용자는 elasticsearch에 필요한 인덱스에 대해 신경 쓸 필요가 없습니다.

    일반 Json 데이터
        [
          {"type":"act","line_id":1,"play_name":"Henry IV",
         
          "speech_number":"","line_number":"","speaker":"","text_entry":"ACT I"},
          {"type":"scene","line_id":2,"play_name":"Henry IV",
          "speech_number":"","line_number":"","speaker":"","text_entry":"SCENE I.London. The palace."},
          {"type":"line","line_id":3,"play_name":"Henry IV",
          "speech_number":"","line_number":"","speaker":"","text_entry":
          "Enter KING HENRY, LORD JOHN OF LANCASTER, the
          EARL of WESTMORELAND, SIR WALTER BLUNT, and others"}
        ]
   
    Kibana와 함께 사용할 json 코드는 다음과 같이 인덱싱되어야 합니다.

    {"index":{"_index":"shakespeare","_id":0}}
    {"type":"act","line_id":1,"play_name":"Henry IV",
    "speech_number":"","line_number":"","speaker":"","text_entry":"ACT I"}
    {"index":{"_index":"shakespeare","_id":1}}
    {"type":"scene","line_id":2,"play_name":"Henry IV",
    "speech_number":"","line_number":"","speaker":"",
    "text_entry":"SCENE I. London. The palace."}
    {"index":{"_index":"shakespeare","_id":2}}
    {"type":"line","line_id":3,"play_name":"Henry IV",
    "speech_number":"","line_number":"","speaker":"","text_entry":
    "Enter KING HENRY, LORD JOHN OF LANCASTER, the EARL
    of WESTMORELAND, SIR WALTER BLUNT, and others"}

    jsonfile - {"index":{"_index":"nameofindex","_id":key}} 에 추가 데이터가 있음을 참고 하세요 .
    Elasticsearch와 호환되는 샘플 json 파일을 변환하기 위해 여기에 Elasticsearch가 원하는 형식으로 제공된 json 파일을 출력하는 php의 작은 코드가 있습니다.

    PHP 코드
        <?php
          $myfile = fopen("todo.json", "r") or die("Unable to open file!"); // your json
          file here
          $alldata = fread($myfile,filesize("todo.json"));
          fclose($myfile);
          $farray = json_decode($alldata);
          $afinalarray = [];
          $index_name = "todo";
          $i=0;
          $myfile1 = fopen("todonewfile.json", "w") or die("Unable to open file!"); //
          writes a new file to be used in kibana dev tool
          foreach ($farray as $a => $value) {
              $_index = json_decode('{"index": {"_index": "'.$index_name.'", "_id": "'.$i.'"}}');
              fwrite($myfile1, json_encode($_index));
              fwrite($myfile1, "\n");
              fwrite($myfile1, json_encode($value));
              fwrite($myfile1, "\n");
              $i++;
          }
        ?>

    https://jsonplaceholder.typicode.com/todos 에서 todo json 파일을 가져 오고 php 코드를 사용하여 Kibana에서 업로드해야 하는 형식으로 변환합니다.

    샘플 데이터를 로드하려면 아래와 같이 개발 도구 탭을 엽니다.
    PHP 코드를 통해 실행한 후 얻은 json 데이터를 가져옵니다.
   
    json 데이터를 업로드하기 위해 개발 도구에서 사용되는 명령은 -

        POST _bulk
            인덱스의 이름은 todo 입니다.

    녹색 버튼을 클릭하면 데이터가 업로드되고 Elasticsearch에서 인덱스가 생성되었는지 여부를 다음과 같이 확인할 수 있습니다.

    다음과 같이 dev 도구 자체에서 동일한 것을 확인할 수 있습니다.
        명령 -
            GET /_cat/indices
           
            index:todo 에서 무언가를 검색하려면 아래와 같이 하면 됩니다.

        개발 도구의 명령

            GET /todo/_search
            todoindex에 있는 모든 레코드를 제공합니다. 우리가 얻는 총 레코드는 200입니다.

감사합니다.

 >
 >
 > Kibana UI에서 dev tools를 이용한 데이터 업로드 방법이 궁금합니다.
 >
 >

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

사이트 정보

회사명 : (주)리눅스데이타시스템 / 대표 : 정정모
서울본사 : 서울특별시 강남구 봉은사로 114길 40 홍선빌딩 2층 / tel : 02-6207-1160
대전지사 : 대전광역시 유성구 노은로174 도원프라자 5층 / tel : 042-331-1161

접속자집계

오늘
1,638
어제
1,251
최대
3,935
전체
832,519
Copyright © www.linuxdata.org All rights reserved.