반응형
들어가기 전
- 아래 내용들은 elasticsearch:7.17.6 버전 기준으로 작성
인덱스 생성
curl -X PUT 'http://localhost:9200/study?pretty'
undefinedcopy
인덱스 조회
curl -X GET 'http://localhost:9200/study?pretty'
undefinedcopy
인덱스 삭제
curl -X DELETE 'http://localhost:9200/study?pretty'
undefinedcopy
전체 인덱스 조회
curl -X GET 'http://localhost:9200/_aliases?pretty'
undefinedcopy
데이터 추가
curl -X PUT 'http://localhost:9200/study/es-students/1?pretty' -H 'Content-Type: application/json' -d ' { "name": "tyler", "age": 30 }'
undefinedcopy
데이터 추가(json 파일)
echo '{"name": "tyler", "age": 30}' > tyler.json
undefinedcopy
curl -X PUT 'http://localhost:9200/study/es-students/1?pretty' -H 'Content-Type: application/json' -d @tyler.json
undefinedcopy
데이터 수정
curl -X POST 'http://localhost:9200/study/es-students/1/_update?pretty' -H 'Content-Type: application/json' -d ' { "doc": { "age": 33 } }'
undefinedcopy
데이터 수정(스크립트)
curl -X POST http://localhost:9200/study/es-students/1/_update?pretty -H 'Content-Type: application/json' -d ' { "script": "ctx._source.age += 5" }'
undefinedcopy
데이터 수정(Bulk 데이터 파일)
echo ' { "index" : { "_index" : "study", "_type" : "es-students", "_id" : "1" } } { "name": "tyler", "age": 30 } { "index" : { "_index" : "study", "_type" : "es-students", "_id" : "2" } } { "name": "tom", "age": 35 } ' > es-students.json
undefinedcopy
curl -X POST 'http://localhost:9200/_bulk?pretty' -H 'Content-Type: application/json' --data-binary @es-students.json
undefinedcopy
데이터 삭제
curl -X DELETE 'http://localhost:9200/study/es-students/1?pretty'
undefinedcopy
데이터 검색 - 전체 색인
curl -X GET 'http://localhost:9200/_search?pretty'
undefinedcopy
응답curl -X GET 'http://localhost:9200/_all/_search?pretty'
undefinedcopy
{
"took": 1, // 조회시 소요된 시간(ms)
"timed_out": false, // 타임아웃 여부
"_shards": {
"total": 1, // 몇 개의 샤드에 질의했는지
"successful": 1, // 몇 개의 샤드에서 성공했는지
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2, // 일치하는 문서의 수
"relation": "eq"
},
"max_score": 1.0, // 일치하는 문서의 최대 점수
"hits": [ // 조회 결과 문서들
{
"_index": "study",
"_type": "es-students",
"_id": "1",
"_score": 1.0, // 일치 점수
"_source": {
"name": "tyler",
"age": 30
}
},
{
"_index": "study",
"_type": "es-students",
"_id": "2",
"_score": 1.0,
"_source": {
"name": "tom",
"age": 35
}
}
]
}
}
undefinedcopy
데이터 검색 - 복수의 색인
curl -X GET 'http://localhost:9200/study,hobby/_search?pretty'
undefinedcopy
데이터 검색 - 복수의 타입
curl -X GET 'http://localhost:9200/study/es-students,docker-students/_search?pretty'
undefinedcopy
데이터 검색 - 전체
- 아래 요청 정보중에 바디 정보 없이 조회해도 동일함
curl -X GET 'http://localhost:9200/study/_search?pretty' -H 'Content-Type: application/json' -d ' { "query": { "match_all": {} } }'
undefinedcopy
데이터 검색 - 조건
curl -X GET 'http://localhost:9200/study/_search?pretty&q=name:tyler'
undefinedcopy
curl -X GET 'http://localhost:9200/study/_search?pretty' -H 'Content-Type: application/json' -d ' { "query": { "term": { "name": "tyler" } } }'
undefinedcopy
curl -X GET 'http://localhost:9200/study/_search?pretty' -H 'Content-Type: application/json' -d ' { "query": { "query_string": { "query": "name:tyler AND age:30" } } }'
undefinedcopy
curl -X GET 'http://localhost:9200/study/_search?pretty' -H 'Content-Type: application/json' -d ' { "query": { "query_string": { "query": "tyler john", "default_field": "name", // default: "_all" "default_operator": "OR" // default: "OR" } } }'
undefinedcopy
curl -X POST 'http://localhost:9200/study/_search?pretty' -H 'Content-Type: application/json' -d ' { "from": 0, "size": 10, "query": { "match": { "name": "tyler" } }, "fields": ["name"] }'
undefinedcopy
매핑 조회
curl -X GET 'http://localhost:9200/study/_mapping?pretty'
undefinedcopy
매핑 추가
curl -X PUT 'http://localhost:9200/study/_mapping?pretty' -H 'Content-Type: application/json' -d ' { "es-students": { "properties": { "email": { "type": "text" } } } }'
undefinedcopy
데이터 집계
curl -X GET http://localhost:9200/study/_search?pretty -H 'Content-Type: application/json' -d ' { "size": 0, "aggs": { "avg_age": { "avg": { "field": "age" } }, "max_age": { "max": { "field": "age" } }, "sum_age": { "sum": { "field": "age" } } } }'
undefinedcopy
curl -X GET http://localhost:9200/study/_search?pretty -H 'Content-Type: application/json' -d ' { "size": 0, "aggs": { "stats_age": { "stats": { "field": "age" } } } }'
undefinedcopy
반응형
'Development > ELK' 카테고리의 다른 글
[Logstash] 설치 (0) | 2019.03.01 |
---|---|
[Elasticsearch] 개념 (0) | 2019.02.24 |
[Kibana] 설치 (0) | 2019.02.24 |
[Elasticsearch] 파이프라인 (0) | 2019.02.23 |
[Elasticsearch] 설치 (2) | 2019.02.23 |