public static void main(String[] args) {
Node node = nodeBuilder().clusterName("somethingstupid").client(true).node();
Client client = node.client();
String json =
"{\"user\":\"kimchy\"," +
"\"postDate\":\"2013-01-30\"," +
"\"message\":\"trying out Elastic Search\"}";
IndexResponse response = client.prepareIndex("testindex", "article")
.setSource(json)
.execute()
.actionGet();
}
为什么在eclipse中需要9-12秒才能将其编入索引?
Centosx64 6.4,ES 0.90.7,2GB内存,没有其他运行,Sysmon显示使用3%cpu和800MB RAM at PEAK(DURING INDEX)。
示例线程:
public class TestPostMethod2 implements Runnable{
public static Node node = nodeBuilder().clusterName("somethingstupid").client(true).node();
public static Client client = node.client();
public void run() {
String json =
"{\"user\":\"kimchY\"," +
"\"postDate\":\"2016-01-30\"," +
"\"message\":\"trying out Elastic Search\"}";
IndexResponse response = client.prepareIndex("testindex", "article")
.setSource(json)
.execute()
.actionGet();
}
public static void main(String[] args) throws IOException {
(new Thread(new TestPostMethod2())).start();
}
}
答案 0 :(得分:2)
创建完整的elasticsearch节点需要时间。 在实际项目中,一旦获得客户端,您只需在所有线程中共享它。
索引部分应该很快。
如果您想索引更多文档,请考虑使用批量API。