Java クライアントの ElasticSearch ドキュメントに従っています。ElasticSearch を開始しました。Rest API を使用して操作できます。Java クライアントを使用したいのですが、これまでのところ、次のようなメインがあります。
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();
}
}
}
Java ログには、127.0.0.1:9300 との接続があることがわかります。しかし、「prepare index」コマンドの後、エラーは表示されず、何も出力されません (システム出力コマンドがいくつかあります)。ElasticSearch のログも相対的なものではありません。Rest API でインデックスを作成すると、これがログに表示されます。