2020년 11월 10일 화요일

[elasticsearch 6.8.13] curl 을 이용한 사용법 예제

개념

elasticsearch , RDBMS 비교

1. index -> database

2. type -> table

3. document -> row

4. mapping -> scheme


** elastic version 에 따라 차이가 있음

curl -XGET localhost:9200 -> 버전및 정보 확인

curl -XGET localhost:9200/test?pretty ->  test 란 인덱스가 존재하는지 확인한다.

curl -XPUT localhost:9200/test?pretty -> test 라는 인덱스 생성

curl -XPOST localhost:9200/test/type1/1/ -d application/json'' -H 'Content-type:a

-> 

test 라는 인덱스에 type1 이라는 type 생성, id 는 1 의 document 로

{"test":"value"} 를 추가한다. 

이미 존재하는 아이디일경우 업데이트되고  XPUT 으로 혼용 가능하다.

-d @파일명 을 하게되면 파일에 정의된 json 문자열 파일 데이터가 

curl -XDELETE localhost:9200/test/type1/1/ -> test 인덱스의 type1 타입의 아이디가 1

인 document 삭제

curl -XGET localhost:9200/test/type1/1?pretty -> document 확인

인덱스에 매핑 정의


document attribute 데이터 타입을 정의한다.


elasticsearch 5.x 버전에서는 타입별 매핑설정이 가능 했으나  6.x 부터는 설정값에 따라 선택

적으로 가능하지만 비추천이고 8.x 때까지는 완전 없앤다고 함.


일단 매핑을 설정 하고 데이터를 넣어야하기 때문에 인덱스 삭제


curl -XDELETE localhost:9200/test?pretty


인덱스생성


curl -XPUT localhost:9200/test?pretty


mapping.json 파일 내용  ->  tt 라는 타입으로 test 라는 propertie 를 갖으며 타입은 text 임

{

        "tt":{

                "properties":{

                        "test" : {

                                "type" : "text"

                        }

                }

        }

}


매핑을 적용


curl -XPUT localhost:9200/test/tt/_mapping?pretty -H 'Content-type:application/json' -d @mapping.json


데이터 잘들어가는거 확인

curl -XPOST localhost:9200/test/tt/1/ -d '{"test":"hahaha"}' -H 'Content-type:application/json'


벌크로 데이터 넣기

bulkdata.json -> 첫줄-인덱스,타입,아이디 두번째줄-도큐먼트형식

{"index":{"_index":"test","_type":"tt","_id":"2"}}

{"test" : "test2"}

{"index":{"_index":"test","_type":"tt","_id":"3"}}

{"test" :"test3"}


url -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/_bulk?pretty' --data-binary @bulkdata.json


데이터 확인 -> 1,2,3 번째 데이터 확인

curl -XGET localhost:9200/test/tt/1?pretty

curl -XGET localhost:9200/test/tt/2?pretty

curl -XGET localhost:9200/test/tt/3?pretty


검색하기.



















댓글 없음:

댓글 쓰기

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

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