본문 바로가기
Infra/검색엔진

EL 에서 데이터 입력/조회/삭제/업데이트 테스트

by 골든크랩 2023. 10. 27.
728x90
반응형

 

docker exec -u 0 -it nifi bash

 

테스트는 EL 8.7.0 에서 진행함

 

아래 테스트를 진행하려니, 아래와 같은 응답을 받음

curl: (52) Empty reply from server

 

 

https 를 사용하니 다시 아래와 같은 응답을 받음.

 

elasticsearch@5f61a9282584:/etc/init.d$ curl -XGET https://localhost:9200/classes?pretty
curl: (60) SSL certificate problem: self signed certificate in certificate chain
More details here: https://curl.haxx.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
elasticsearch@5f61a9282584:/etc/init.d$

 

해결법은 다음글을 참조함

https://citizen.tistory.com/47?category=983889

 

ElasticSearch curl: (60) SSL certification problem

1. 에러 내용 ElasticSearch 엔진 설치 이후, curl 명령어로 서버에 쿼리를 요청하면서 발생할 수 있는 에러입니다. 2. 원인 curl 명령어로 HTTPS 사이트에 접근할 때는 SSL 인증서를 체크하도록 되어 있습

citizen.tistory.com

 

vim /usr/share/elasticsearch/config/elasticsearch.yml

xpack.security.enabled : false   ==> 로 수정

elasticsearch -d   ==> 시스템 재기동, 도커컨테이너 재기동 시킬것.

 

 

 

1. 기존에 있는지 검색

curl -XGET http://localhost:9200/classes

좀더 깔금하게 보기

curl -XGET http://localhost:9200/classes?pretty

 

2. 인덱스 생성

curl -XPUT http://localhost:9200/classes

 

3. 인덱스 삭제

curl -XDELETE http://localhost:9200/classes

 

4. 데이터 입력

인덱스명/타입명/id -d '데이터' 순으로 입력

 

---> 아래 방식은 이제 동작안함. EL V8.에서는...

curl -XPOST http://localhost:9200/classes/class/1 -d '{"title":"Algrithm", "professor":"John"}'
{"error":"no handler found for uri [/classes/class/1] and method [POST]"}elasticsearch@5f61a9282584:~$ 

 

 

수정1) 실패. 

curl -XPOST http://localhost:9200/classes/_doc/1 -d '{"title":"Algrithm", "professor":"John"}'

----> {"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}elasticsearch@5f61a9282584:~$ 

 

수정2) 성공..Content-Type이 들어가야 함

curl -XPOST http://localhost:9200/classes/_doc/1  -H "Content-Type: application/json"  -d '{"title":"Algrithm", "professor":"John"}'

 

구글링한 샘플)

curl -k -XPOST 'https://localhost:9200/blog_article/_doc/1' -H "Content-Type: application/json" -d '{"title": "New version of Elasticsearch released!", "content": "Version 2.2 released today!", "priority": 10, "tags": ["announce", "elasticsearch", "release"] }'

 

 

5. 데이터 조회

curl -XGET http://localhost:9200/classes/_doc/1?pretty

 

6. 파일로 데이터 입력

샘플 oneclass.json

{
  "title" : "Machine Learing",
  "professor" : "Dennis Chae",
  "major" : "Computer Science",
  "semester" : ["spring", "fall"],
  "student_count" : 100,
  "unit" : 3,
  "rating" : 5
}

 

curl -XPOST http://localhost:9200/classes/_doc/2  -H "Content-Type: application/json"  -d @oneclass.json

 

 

 

■ 업데이트

 

docker exec -u 0 -it 5f61a9282584  bash

curl -XPOST http://localhost:9200/classes/_doc/1  -H "Content-Type: application/json"  -d '{"title":"Algrithm", "professor":"John"}'

curl -XGET http://localhost:9200/classes/_doc/1?pretty


curl -XPOST http://localhost:9200/classes/_update/1?pretty -H'Content-Type: application/json' -d '{"doc":{"unit":1}}'

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

728x90
반응형

'Infra > 검색엔진' 카테고리의 다른 글

용어 정리  (0) 2023.10.31
EL 구조  (0) 2023.10.27
EL과 RDB 비교  (0) 2023.10.27
kibana 설치하기 (8.7.0)  (0) 2023.08.30
Elasticsearch 도커 설치  (0) 2023.08.30

댓글