title: Elasticsearch Java API Index Document
body: <ol>
  <li><p>Downloaded .90.6, Unpacked, moved Elastic Search to /usr/share/elasticsearch (with chmod 777 -R permissions on centosx64 6.4), renamed cluster to <em>somethingstupid</em> and started server.</p></li>
  <li><p>Installed plugins <a href="https://github.com/mobz/elasticsearch-head" rel="nofollow">ESHead</a> and <a href="https://github.com/OlegKunitsyn/elasticsearch-browser" rel="nofollow">ESBrowser</a> b/c Im new and need it (am used to Solr's nice ui). This way I know the server is running too.</p></li>
  <li><p>I can create an index via curl : <code>curl -XPOST 'http://localhost:9200/testindex'</code> and delete it too: <code>curl -XDELETE 'http://localhost:9200/testindex'</code></p></li>
  </ol>
  
  <p>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? </p>
  
  <pre><code>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&lt;String, Object&gt; putJsonDocument(String title, String content, Date postDate, String author){
  
              Map&lt;String, Object&gt; jsonDocument = new HashMap&lt;String, Object&gt;();
  
              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();
          }
  
  
  }
  </code></pre>
  
  <p>My Source: <a href="http://java.dzone.com/articles/elasticsearch-java-api" rel="nofollow">http://java.dzone.com/articles/elasticsearch-java-api</a>. Everything else including the elastic documentation failed one way or another....(The method jsonBuilder() is undefined for the type PostES).</p>
  
  <p>According to documentation I should be able to do this. But it does nothing either:</p>
  
  <pre><code>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();
      }
  
  }
  </code></pre>