To issue 1: you create a single node cluster without index, and a client of
it.

To issue 2: you see the UnavailableShardsException caused by a timeout
while indexing to a replica shard. This means, you may have set up a single
node cluster, but with replica level 1 (default) which needs 2 nodes for
indexing. Maybe there was once another node joining the cluster and ES
wants it back abut it never came (after 60 secs). Then ES returns the
timeout error. Maybe replica level 0 helps. You should also check the
cluster health. A color of green shows everything works, yellow means there
are too few nodes to satisfy the replica condition, and read means the
cluster is not in a consistent/usable state.

To issue 3: not sure what clusterName() means. I would use settings and add
a field "cluster.name". Maybe it is equivalent. You must ensure you use the
same "cluster.name" setting throughout all nodes and clients. You also can
not reuse data from clusters that had other names (look into the "data"
folder)

To issue 4: ES takes ~5 secs for discovery, the zen modules pings and waits
for responding master nodes by default. If you just test locally on your
developer machine, you should disable zen. Most easily by disabling
networking at all, by using NodeBuilder.nodeBuilder().local(true)...

Jörg




On Mon, Jul 21, 2014 at 6:53 PM, Alain Désilets <[email protected]>
wrote:

> I am trying to get started with the Java API, using the excellent tutorial
> found here:
>
>    http://www.slideshare.net/dadoonet/hands-on-lab-elasticsearch
>
> But I am still having a lot of trouble.
>
> Below is a sample of code that I have written:
>
> package ca.nrc.ElasticSearch;
>
> import org.codehaus.jackson.map.ObjectMapper;
> import org.elasticsearch.action.get.GetResponse;
> import org.elasticsearch.action.index.IndexResponse;
> import org.elasticsearch.client.Client;
> import org.elasticsearch.node.NodeBuilder;
>
> public class ElasticSearchRunner {
>
> static ObjectMapper mapper;
> static Client client;
> static String indexName = "meal5";
> static String typeName = "beer";
> static long startTimeMSecs;
>
> public static void main(String[] args) throws Exception {
> startTimeMSecs = System.currentTimeMillis();
> mapper = new ObjectMapper(); // create once, reuse
>  echo("Creating the ElasticSearch client...");
> client = NodeBuilder.nodeBuilder().node().client(); // Does this create a
> brand new cluster?
> // client =
> NodeBuilder.nodeBuilder().clusterName("handson").client(true).node().client();
> // Joins existing cluster called "handson"
> echo("DONE creating the ElasticSearch client... Elapsed time =
> "+elapsedSecs()+" secs.");
>  echo("Creating a beer object...");
> Beer beer = new Beer("Heineken", Colour.PALE, 0.33, 3);
> String jsonString = mapper.writeValueAsString(beer);
> echo("DONE Creating a beer object...");
>
> echo("Indexing the beer object...");
> IndexResponse ir = null;
> ir = client.prepareIndex(indexName, typeName).setSource(jsonString)
> .execute().actionGet();
> echo("DONE Indexing the beer object...");
>
> echo("Retrieving the beer object...");
> GetResponse gr = null;
> gr = client.prepareGet(indexName, typeName, ir.getId()).execute()
> .actionGet();
> echo("DONE Retrieving the beer object...");
> }
>
>  public static float elapsedSecs() {
> float elapsed = (System.currentTimeMillis() - startTimeMSecs)/1000;
> return elapsed;
> }
>  public static void echo(String mess) {
> mess = mess + " (Elapsed so far: "+elapsedSecs()+" seconds)";
> System.out.println(mess);
> }
> }
>
>
> It works, "sort of"...
>
> If I use the first method for creating the client:
>
> client = NodeBuilder.nodeBuilder().node().client();
>
> Then it works fin the first time I run it. However:
>
> *** ISSUE 1: If I try to inspect the meal index with Marvel, I don't find
> it.
>
> Also,
>
> *** ISSUE 2: If I run the application a second time, I get the following
> output:
>
> Creating the ElasticSearch client... (Elapsed so far: 0.0 seconds)
> log4j:WARN No appenders could be found for logger (org.elasticsearch.node).
> log4j:WARN Please initialize the log4j system properly.
> log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
> more info.
> DONE creating the ElasticSearch client... Elapsed time = 9.0 secs.
> (Elapsed so far: 9.0 seconds)
> Creating a beer object... (Elapsed so far: 9.0 seconds)
> DONE Creating a beer object... (Elapsed so far: 9.0 seconds)
> Indexing the beer object... (Elapsed so far: 9.0 seconds)
> Exception in thread "main"
> org.elasticsearch.action.UnavailableShardsException: [meal5][0] [2]
> shardIt, [0] active : Timeout waiting for [1m], request: index
> {[meal5][beer][B3F5ZEmSTruqdnlxhYviFg],
> source[{"brand":"Heineken","colour":"PALE","size":0.33,"price":3.0}]}
> at
> org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.raiseTimeoutFailure(TransportShardReplicationOperationAction.java:526)
> at
> org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$3.onTimeout(TransportShardReplicationOperationAction.java:516)
> at
> org.elasticsearch.cluster.ClusterStateObserver$ObserverClusterStateListener.onTimeout(ClusterStateObserver.java:239)
> at
> org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(InternalClusterService.java:494)
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> at java.lang.Thread.run(Thread.java:722)
>
>
> For me to be able to run the application again, I have to change the
>  indexName variable to a different value (ex: "meal6").
>
> Also:
>
> *** ISSUE 3: If I try using the second method for creating a Client, then
> it doesn't work. More specifically, if I use this method:
>
> client =
> NodeBuilder.nodeBuilder().clusterName("handson").client(true).node().client();
>
> This yields:
>
> Creating the ElasticSearch client... (Elapsed so far: 0.0 seconds)
> log4j:WARN No appenders could be found for logger (org.elasticsearch.node).
> log4j:WARN Please initialize the log4j system properly.
> log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for
> more info.
> DONE creating the ElasticSearch client... Elapsed time = 34.0 secs.
> (Elapsed so far: 34.0 seconds)
> Creating a beer object... (Elapsed so far: 34.0 seconds)
> DONE Creating a beer object... (Elapsed so far: 34.0 seconds)
> Indexing the beer object... (Elapsed so far: 34.0 seconds)
> Exception in thread "main"
> org.elasticsearch.discovery.MasterNotDiscoveredException: waited for [1m]
> at
> org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$4.onTimeout(TransportMasterNodeOperationAction.java:170)
> at
> org.elasticsearch.cluster.ClusterStateObserver$ObserverClusterStateListener.onTimeout(ClusterStateObserver.java:239)
> at
> org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(InternalClusterService.java:494)
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> at java.lang.Thread.run(Thread.java:722)
>
> Yet, the "handson" cluster does exist and I can see it in Marvel.
>
> Finally, I am puzzled by the following:
>
> *** ISSUE 4: It seems that it takes ES 8-9 secs to create a Client using
> the first method, and >30 secs  with the second method. That seems really
> high. Is that normal?
>
>
> Any help you can provide with either of those issues will be greatly
> appreciated. Thx.
>
> Alain
>
>
>
>
>
>
>
>
>
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "elasticsearch" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/ba7e38a6-fb11-4a4d-95b6-4b0f2c904061%40googlegroups.com
> <https://groups.google.com/d/msgid/elasticsearch/ba7e38a6-fb11-4a4d-95b6-4b0f2c904061%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/CAKdsXoGYALxCux0iZ749UhWM7gBRHRubCP2zcC7RT2o0eCWDdg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to