프로그래밍/ElasticSearch
(ElasticSearch) JEST mapping 가져오는 방법 (Get Mapping)
rlawlstjd007
2020. 6. 15. 17:30
들어가며
- JEST를 사용하여 Elastics Search DB 서버에 특정 Index의 Mapping 값을 가져오는 방법에 대해서 알아보겠습니다.
- 해당 Index의 Mapping이 생성되어 있다고 가정하겠습니다.
실행환경
- ElasticSeacrh (V5.5.1)
구현방법
- GetMapping 클래스를 이용하여 특정 Index의 Mapping 값을 불러오는 방식입니다.
//DB Server 주소
String elasticAddress = "http://localhost:9200";
//Index 명
String indexName = "";
JestClientFactory factory = new JestClientFactory();
final HttpClientConfig.Builder builder = new HttpClientConfig.Builder(elasticAddress)
.gson(new Gson())
.connTimeout(1000 * 30)
.readTimeout(1000 * 60 * 5)
.multiThreaded(true);
factory.setHttpClientConfig(builder.build());
this.client = factory.getObject();
//Mapping 값 가져오기
JsonObject mapping = getMappings(client, indexName);
public static JsonObject getMappings(JestClient client, String indexName) throws IOException {
GetMapping getMapping = new GetMapping.Builder().addIndex(indexName).build();
JsonObject jsonObject;
try {
jsonObject = client.execute(getMapping).getJsonObject().getAsJsonObject(indexName).getAsJsonObject("mappings")
.getAsJsonObject("doc").getAsJsonObject("properties");
} catch (NullPointerException ex) {
jsonObject = null;
}
return jsonObject;
}
관련글
(ElasticSearch) ElasticSearch 프론트엔드 플러그인 elasticsearch-head 설치 및 사용법
elasticsearch-head ElasticSearch DB 정보 및 쿼리를 Front End 페이지를 통해서 조작할 수 있는 플러그인이다. 아래와 같이 생겼으며 Index리스트 및 상세 정보, Query 입력창 등을 이용할 수 있다. 설치방법..
jinseongsoft.tistory.com
[ElasticSearch] 1. ElasticSearch의 개요
1. ElasticSearch의 개요 "Search is something that any application should have" - Shay Banon (Creator of ElasticSearch) 1.1 History of ElasticSearch 2004년, Shay Banon이 Compass 라는 제품 개발을 했고..
jinseongsoft.tistory.com
반응형