모든 색인 나열/ 생성
Elastic Search1. 색인 나열
> curl http://127.0.0.1:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
# 색인이 없는 상태
2. 색인 생성
> curl -X PUT http://127.0.0.1:9200/customer?pretty # pretty =JSON응답을 pretty-print
{
"acknowledged" : true,
"shards_acknowledged" : true
}
> curl http://127.0.0.1:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open customer 7K4E9D24SKmUMznoVYcL7w 5 1 0 0 650b 650b
# customer 라는 색인이 하나 있으며, pri shard = 5개, replica = 1개.
# yellow : replica = 1 인데, 노드가 1개뿐임. 노드 추가해야 green 이 됨.
3. 문서 색인화 및 쿼리
호줄할 내용)
PUT /customer/external/1?pretty
{
"name": "John Doe"
}
호출 방법 1.curl)
curl -X PUT -H "Content-Type: application/json; charset=utf-8" -d '{"name":"John Doe"}' http://172.16.174.148:9200/customer/external/1?pretty
호출 방법 2.postman)
PUT + http://172.16.174.148:9200/customer/external/1?pretty 선택
BODY + raw + json 선택
{ "name": "John Doe" } 입력
결과)
{
"_index" : "customer",
"_type" : "external",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"created" : true
}
* 같은 ID ( 위 경우에는 1 ) 로 한 번 더 호출하면 (이름을 바꿔서) 업데이트(DELETE+INSERT)가 됨.
4) 앞서 id=1 로 했으나, 지정하지 않을 수 있다. 이 경우 Random ID 가 사용된다. ( POST 사용)
POST /customer/external?pretty
{
"name": "Jane Doe"
}
{
"_index": "customer",
"_type": "externa",
"_id": "AWpnuFPmHm_5zNNoJ_8z",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": true
}
5) 문서 업데이트
- 문서 업데이트
POST /customer/external/1/_update?pretty
{
"doc":{"name":"Jane Doe"}
}
- 문서 업데이트 및 필드 추가
POST /customer/external/1/_update?pretty
{
"doc":{"name":"Jane Doe","age":20}
}
- 스크립트를 이용한 업데이트
POST /customer/external/1/_update?pretty
{
"script":"ctx._source.age += 5"
}
6) 문서 삭제
- 한 ID 삭제
DELETE /customer/external/2?pretty
- 매칭 삭제
https://www.elastic.co/guide/en/elasticsearch/reference/5.4/docs-delete-by-query.html
POST twitter/_delete_by_query
{
"query": {
"match": {
"message": "some message"
}
}
}
- 전체 삭제
POST twitter,blog/tweet,post/_delete_by_query
{
"query": {
"match_all": {}
}
}
7) 배치 처리
- 2개의 Document 인덱싱 처리
POST /customer/external/_bulk?pretty
{"index":{"_id":"1"}}
{"name":"John Doe"}
{"index":{"_id":"2"}}
{"name":"Jane Doe"}
- 업데이트와 딜리트 동시 처리. 오류나도 처리는 계속됨. 처리결과반환시에 알수 있음.
POST /customer/external/_bulk?pretty
{"update":{"_id":"1"}}
{"doc":{"name":"John Doe becomes Jane Doe"}}
{"delete":{"_id":"2"}}
'Elastic Search' 카테고리의 다른 글
검색 실행 (0) | 2019.04.30 |
---|---|
데이터 탐색.샘플데이터 집합 로드 (0) | 2019.04.29 |
매뉴얼-https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html (0) | 2019.04.28 |
클러스터 상태 보기 (0) | 2019.04.28 |
설치 (0) | 2019.04.28 |