1) host, port 주입
RestClient restClient = RestClient.builder(
new HttpHost("localhost", 9200, "http"),
new HttpHost("localhost", 9201, "http")).build();
BulkRequest.Builder br = new BulkRequest.Builder();
ElasticsearchTransport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
ElasticsearchClient esClient = new ElasticsearchClient(transport);
2) String으로 된 JSON 데이터 정의
String json = "{\"test\":1}"
Reader input = new StringReader(json);
IndexRequest<JsonData> request = IndexRequest.of(i -> i
.index("test-log") //set index
.withJson(input)
);
3) 전송
IndexResponse response = esClient.index(request);
log.info("Indexed with version " + response.version());
출처
Initialization | Elasticsearch Java API Client [7.17] | Elastic
A RestClient instance can be built through the corresponding RestClientBuilder class, created via RestClient#builder(HttpHost...) static method. The only required argument is one or more hosts that the client will communicate with, provided as instances of
www.elastic.co
https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/7.17/indexing.html
Indexing single documents | Elasticsearch Java API Client [7.17] | Elastic
Indexing single documentsedit The Java API Client offers several ways to index data: you can provide application objects that will be automatically mapped to JSON, or you can provide raw JSON data. Using application objects is more suited to applications w
www.elastic.co
'빅데이터 > Elasticsearch' 카테고리의 다른 글
RestHighLevelClient로 구현한 idempotence 데이터 적재 (0) | 2022.11.29 |
---|---|
엘라스틱서치에 중복 id로 값을 보내면? (0) | 2020.09.27 |
Elasticsearch, Logstash, Kibana 버젼별 하위호환표 (0) | 2020.03.26 |
엘라스틱서치에서 field 와 field.keyword 의 차이(text와 keyword) (0) | 2020.03.06 |
Python으로 elasticsearch에 document 넣기 예제 및 결과물 (257) | 2019.08.07 |