您的位置:首页 > 其它

Elasticsearch 5.1.1 Embedded Mode

2017-01-09 14:31 239 查看
Elasticsearch 5.1.1 与2.X的Embedded Mode有了较大不同。搭梯子查了一下,在此做个记录:

Node节点要做一下扩充

public class EmbedNode extends org.elasticsearch.node.Node{
public EmbedNode(Settings preparedSettings, Collection<Class<? extends Plugin>> classpathPlugins) {
super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), classpathPlugins);
}

}


建立服务类,提供查询Client,用到了Netty4,请导入相应的包

public class EmbedSearchServer{
private Node node;
private EmbedSearchServer(){};
public EmbedSearchServer(String dataPath){
node = new EmbedNode(
Settings.builder()
.put("transport.type", "netty4")
.put("http.type", "netty4")
.put("http.enabled", "true")
.put("path.home", "classpath")
.put("path.data", dataPath)
.build(),
Arrays.asList(Netty4Plugin.class)
);
}
public void start() throws NodeValidationException{
node.start();
}
public void stop() throws IOException{
node.close();
}
public Client getClient() {
return node.client();
}
}


一个简单使用例子:

new EmbedSearchServer(/*your data path*/).getClient().search(/*SearchRequest*/)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Embedded elasticsearch