We are migrating from Spring Boot 1.x (comes with Elastic 2) to
Spring Boot 2.x (comes with Elastic 5)
In Spring boot 1 (i.e Elastic 2), we've used the NodeBuilder api to create in memory nodes on demand.
With SpringBoot 2(i.e Elastic 5), Nodebuilder is not available, we tried using below code:
File tmpDir = File.createTempFile("elastic",Long.toString(System.nanoTime()));
Settings settings = Settings.builder()
.put("http.enabled", true)
.put("index.number_of_shards", "1")
.put("path.data", new File(tmpDir, "data").getAbsolutePath())
.put("path.logs", new File(tmpDir, "logs").getAbsolutePath())
.put("path.work", new File(tmpDir, "work").getAbsolutePath())
.put("transport.tcp.port", "9300")
.put("network.host", "localhost")
.put("node.data", "true")
.put("node.master", "true")
.put("path.home", tmpDir)
.put("transport.type", "local").build();
return new ElasticsearchTemplate(new Node(settings).start().client());
When we try to access the ElasticsearchRepository, it is giving below exception:
NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{6gkUXEX6Rsyowd928D0k_A}{localhost}{127.0.0.1:9200}]]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:347)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:245)
at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59)
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:363)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:408)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54)
at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.doCount(ElasticsearchTemplate.java:495)
at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.count(ElasticsearchTemplate.java:473)
at org.springframework.data.elasticsearch.repository.support.AbstractElasticsearchRepository.count(AbstractElasticsearchRepository.java:150)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:377)
at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:641)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:605)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:590)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy139.count(Unknown Source)
at com.werner.ecp.elastic.service.carrier.ElasticCarrierServiceImpl.getCarrierCount(ElasticCarrierServiceImpl.java:58)
at com.werner.ecp.elastic.service.carrier.ElasticCarrierServiceImpl$FastClassBySpringCGLIB$e96152a4.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
Any thoughts on what am missing? appreciate your help!
Embedding Elasticsearch into your application like this isn't really a recognised way of running Elasticsearch any more. This blog post from 2016 describes the reasoning for this decision.
It may be possible to get it to work like this still, but it's not something we cover in any tests so it might be fragile and difficult to debug. If at all possible, you should run Elasticsearch as a standalone process instead.
If we move out of 'embedded Elastic server within the application' and move into external standalone elastic search server, how do we set up clustering?
In production, our application runs on 4 servers . Does that mean we need to run Elastic search instance on these 4 DMZ servers? If yes, how do we make sure the 4 Elastic search instance are running in a clustered fashion?
Any feedback/pointers will be highly appreciated!
The setup in your original post did not look like a clustered installation, so perhaps you do not need this? The reference manual covers the configuration needed, particularly this page:
It was not clear from your OP that this was your goal. A resilient Elasticsearch cluster needs at least 3 master-eligible nodes and at least two data nodes (some nodes may be both, so 3 nodes in total).
Although this community forum isn't really the right place to push commercial things, there's no real-time community support offering so the most helpful way I can answer this is to point out that Elastic can help with support and consulting, and this subject matter is also covered in training: Consulting Services for the Elastic Stack | Elastic | Elastic Consulting
For future reference, if you have an unassigned shard, the allocation explain API is the first thing you should look at, as it will try and explain why things couldn't be allocated.
Dave - Now that am able to make some progress on how to set up ES cluster locally, I have my next set of questions for you!
Our current Elastic implementation:
Ours is a SpringBoot (SprinBoot 1.5) application. We have used Spring Boot API to implement Embedded Elastic (i.e its an in-memory elastic instance within the app) and we use Node client to connect to our embedded elastic instance.
What we like to get to:
We are looking to migrate from Embedded Elastic to an External Elastic server.
Migrate from using Node Client and to using a Rest Client
Questions For you:
1) Any pointers you can provide on how we go about migrating our application code from NodeClient to using Rest Client? 2) They talk about Low Level Rest Client and High Level Rest Client. Which one would you recommend us to use? High Level Rest client is available from what version of Elastic?
Not really, I've never done such a migration myself. The client APIs are designed to be quite similar in shape. Are you stuck on something specific?
You should use the High-level REST client as much as possible, but it does not cover 100% of the APIs so you might need to use the Low-level REST client from time to time. You can use both clients in one application (in fact the high-level one is implemented on top of the low-level one).
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.