Downloaded .90.6, Unpacked, moved Elastic Search to /usr/share/elasticsearch (with chmod 777 -R permissions on centosx64 6.4), renamed cluster to somethingstupid and started server.
Installed plugins ESHead and ESBrowser b/c Im new and need it (am used to Solr's nice ui). This way I know the server is running too.
I can create an index via curl :
curl -XPOST 'http://localhost:9200/testindex'and delete it too:curl -XDELETE 'http://localhost:9200/testindex'
When I try creating a new index and indexing a document of type article and viewing it via Java API, eclipse runs the code, shows basic logging in the console, and then closes with no errors. Also, inside my logs the latest line just shows that I have started up elastic search but nothing else. Its like the code isnt even reaching elastic search. No indexes or articles show up after I run the java api. What am I missing?
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.elasticsearch.client.Client;
import org.elasticsearch.node.Node;
import static org.elasticsearch.node.NodeBuilder.*;
public class PostES {
public static void main (String args[]){
PostES p = new PostES();
p.postElasticSearch();
}
public static Map<String, Object> putJsonDocument(String title, String content, Date postDate, String author){
Map<String, Object> jsonDocument = new HashMap<String, Object>();
jsonDocument.put("title", title);
jsonDocument.put("conten", content);
jsonDocument.put("postDate", postDate);
jsonDocument.put("author", author);
return jsonDocument;
}
private void postElasticSearch(){
Node node = nodeBuilder().node();
Client client = node.client();
client.prepareIndex("testindex", "article")
.setSource(putJsonDocument("Example Title",
"This description is so important. You don't even know!",
new Date(),
"J.R."))
.execute().actionGet();
node.close();
}
}
My Source: http://java.dzone.com/articles/elasticsearch-java-api. Everything else including the elastic documentation failed one way or another....(The method jsonBuilder() is undefined for the type PostES).
According to documentation I should be able to do this. But it does nothing either:
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.node.Node;
public class TestPostMethod2 {
public static void main(String[] args) {
Node node = nodeBuilder().local(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();
}
}