0
Java 클라이언트에 대한 ElasticSearch 설명서를 따르고 있습니다. ElasticSearch를 시작했으며 나머지 API와 상호 작용할 수 있습니다. 나는 자바 클라이언트를 사용하려면 지금까지 나는이 같은 주요 있습니다Java 전송 클라이언트로 ElasticSearch에 연결하는 방법은 무엇입니까?
public class TestElastic {
public static void main(String[] args) {
try{
TransportClient client = TransportClient.builder().build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));
JSONObject place = new JSONObject();
place.put("name", "AAAAA");
IndexResponse response = client.prepareIndex("my_database", "places", "1")
.setSource(place)
.get();
System.out.println(response.toString());
// Index name
String _index = response.getIndex();
System.out.println(_index);
// Type name
String _type = response.getType();
System.out.println(_type);
// Document ID (generated or not)
String _id = response.getId();
System.out.println(_id);
// Version (if it's the first time you index this document, you will get: 1)
long _version = response.getVersion();
System.out.println(_version);
// isCreated() is true if the document is a new one, false if it has been updated
boolean created = response.isCreated();
System.out.println(created);
client.close();
}catch (Exception ex){
ex.printStackTrace();
}
}
} 자바 로그에서
내가 127.0.0.1:9300와의 연결이 있음을 알 수있다. 그러나 "인덱스 준비"명령을 수행 한 후에 오류가 표시되지 않고 아무 것도 인쇄되지 않습니다 (일부 시스템 출력 명령이 있음). ElasticSearch 로그에서 아무것도 상대적인 것도 아닙니다. Rest API를 사용하여 색인을 만들면 로그에서 확인할 수 있습니다.
catch 블록에'ex.printStackTrace();'를 추가하면 예외가 있는지 확인할 수 있습니까? 당신은 조용히 그것을 삼키고 있습니다 ;-) – Val
당신 말이 맞아요. 어떻게 내가 이것을 놓칠 수 있니? –