Hello!
Just tested your code with ES 0.19.4 - no problem with connecting to my local instance with the code exactly copy pasted from your post.
Are you sure, your ElasticSearch instance listens on localhost ?
--
Regards,
Rafał Kuć
Sematext :: http://sematext.com/ :: Solr - Lucene - Nutch - ElasticSearch
Hi Rafal,
Here you go..
import static org.elasticsearch.node.NodeBuilder.*;
import static org.elasticsearch.common.xcontent.XContentFactory.*;
import java.io.IOException;
import java.util.Date;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;
public class Main {
public static void main(String[] args) {
TransportClient client = new TransportClient(ImmutableSettings.settingsBuilder().put("<a style=" font-family:'courier new'; font-size: 9pt;" href="http://cluster.name">cluster.name</a>", "elasticsearch").build());
client.addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
try {
IndexResponse response = client
.prepareIndex("testtweet", "tweet1", "0")
.setSource(
jsonBuilder()
.startObject()
.field("user", "kimchy")
.field("postDate", new Date())
.field("message",
"trying out Elastic Search")
.endObject()).execute().actionGet();
System.out.println("Done");
} catch (ElasticSearchException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//node.close();
}
}
On Fri, Jun 29, 2012 at 7:34 PM, Rafał Kuć <r.kuc@solr.pl> wrote:
Hello!
This usually means that the client can't connect to the cluster. Could you post the code ?
--
Regards,
Rafał Kuć
Sematext ::
http://sematext.com/ :: Solr - Lucene - Nutch - ElasticSearch
Hi Rafal,
Now I get "org.elasticsearch.client.transport.NoNodeAvailableException"
I dont see any problems while indexing contents thru cURL...
Thanks,
Baahu
On Fri, Jun 29, 2012 at 7:14 PM, Rafał Kuć <r.kuc@solr.pl> wrote:
Hello!
Can you try connecting with the TransportClient. This code should do the work:
TransportClient client = new TransportClient(ImmutableSettings.settingsBuilder().put("cluster.name", "elasticsearch").build());
client.addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
--
Regards,
Rafał Kuć
Sematext ::
http://sematext.com/ :: Solr - Lucene - Nutch - ElasticSearch
Hi Rafał,
I get the exception org.elasticsearch.discovery.MasterNotDiscoveredException: .
I set the clustername to "elasticsearch" (In elasticsearch.yml the cluster.name is set to elasticsearch.)
Thanks,
Baahu
On Fri, Jun 29, 2012 at 6:40 PM, Rafał Kuć <r.kuc@solr.pl> wrote:
Hello!
I think you are starting a new node, instead of connecting to your instance. Try the following:
Client client = NodeBuilder.nodeBuilder().client(true).clusterName(clusterName).node().client();
Instead of your:
"
Node node = NodeBuilder.nodeBuilder().node().start();
Client client = node.client ();
"
Please notice that you need to provide a cluster name.
--
Regards,
Rafał Kuć
Sematext :: http://sematext.com/ :: Solr - Lucene - Nutch - ElasticSearch
Hi,
Below is a sample program to index some content to the ES running in localhost on 9200.But I dont see this indexing the content, I dont see the testtweet folder being created in the data folder.I am trying this in windows.
public class Main {
public static void main(String[] args) {
Node node = NodeBuilder.nodeBuilder().node().start();
Client client = node.client ();
try {
IndexResponse response = client
.prepareIndex("testtweet", "tweet1", "0")
.setSource(
jsonBuilder()
.startObject()
.field("user", "kimchy")
.field("postDate", new Date())
.field("message",
"trying out Elastic Search")
.endObject()).execute().actionGet();
System.out.println("Done");
} catch (ElasticSearchException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
node.close();
}
}
--
Twitter:http://twitter.com/Baahu
--
Twitter:http://twitter.com/Baahu
--
Twitter:http://twitter.com/Baahu