title: query elasticsearch with java with JSON
body: <p>I'm using elasticsearch 1.3.1 and i want to query it with java SPRING &amp; elastic java API.</p>
  
  <p>I use Angularjs for front-end and i can query elasticsearch very well. </p>
  
  <p>What i want to do is :</p>
  
  <p>1) create the json query for elasticsearch with angularjs : ok</p>
  
  <pre><code>    {
      "bool" : {
          "must" : [{"query_string" : {   "query" : "***"}}],
          "must_not" : [
              {"term" : {"O_LIFESTAGE" : "lymphe" }}, 
              {"term" : {"O_SEX" : "m"}}, 
              {"term" : {"L_CONTINENT" : "europe" }}, 
              {"term" : {"I_INSTITUTIONCODE" : "herbierparis"}}, 
              {"term" : {"I_INSTITUTIONCODE" : "herbiercaen"}}, 
              {"term" : {"I_INSTITUTIONCODE" : "herbiertoulouse"}}
          ]
      }
  }
  </code></pre>
  
  <p>2) to call a java SPRING rest web service and send it the json query created in 1) : ok</p>
  
  <p>3) the web service query elasticsearch with the query created in 1) and save the result ( list of ids) : i failed, i get an error ( nested exception is org.elasticsearch.indices.IndexMissingException: [donnees] missing ) with the follow code :</p>
  
  <pre><code>Node node = nodeBuilder().clusterName("elasticsearch noeud 1").node();
  Client client = node.client();
  String myquery = "{\"bool\": {\"must\": [{\"query_string\": {\"query\": \"***\"}}],\"must_not\": [{\"term\": {\"O_LIFESTAGE\": \"lymphe\"}},{\"term\": {\"O_SEX\": \"m\"}},{\"term\": {\"L_CONTINENT\": \"europe\"}},{\"term\": {\"I_INSTITUTIONCODE\": \"herbierparis\"}},{\"term\": {\"I_INSTITUTIONCODE\": \"herbiercaen\"}},{\"term\": {\"I_INSTITUTIONCODE\": \"herbiertoulouse\"}}]}}";
  //WrapperQueryBuilder querybuilder= new WrapperQueryBuilder(query) ;
  
  //try to get it work with an easy query before trying with "myquery"
  SearchResponse searchResponse = client.prepareSearch("donnees").setTypes("specimens").setQuery("{\"term\": {\"L_CONTINENT\": \"europe\"}}").execute().actionGet();
  
  SearchHit[] results = searchResponse.getHits().getHits();
  System.out.println("Current results: " + results.length);
  for (SearchHit hit : results) {
      System.out.println("------------------------------");
      Map&lt;String,Object&gt; result = hit.getSource();   
      System.out.println(result);
  }
  node.close();
  </code></pre>
  
  <hr>
  
  <hr>
  
  <p>this is how i create my elasticsearch index :</p>
  
  <pre><code> curl -XPOST 'localhost:9200/donnees'
  </code></pre>
  
  <p>this is the index mapping :</p>
  
  <pre><code>curl -XPUT 'localhost:9200/donnees/specimens/_mapping' -d '{
  "specimens" : {
      "_all" : {"enabled" : true},
      "_index" : {"enabled" : true},
      "_id" : {"index": "not_analyzed", "store" : false},
      "properties" : { ... }}}'
  </code></pre>
  
  <p>the data import : </p>
  
  <pre><code>curl -XPUT 'localhost:9200/_river/donnees_s/_meta' -d '{
   "type" : "jdbc",
   "jdbc" : {
      "index" : "donnees",
      "type" : "specimens",
      "url" : "jdbc:oracle:thin:@localhost:1523:recolnat",
       "user" : "user",
       "password" : "pass",
       "sql" : "select * from all_specimens_data"
   }}'
  </code></pre>
  
  <p>Example of query i try to do in java, working well in curl &amp; JS : </p>
  
  <pre><code>curl -XGET 'http://localhost:9200/donnees/specimens/_search?size=100000000' -d '
  {
  "fields" : ["O_OCCURRENCEID"],
  "query" :     {
      "bool" : {
          "must" : [{"query_string" : {   "query" : "***"}}],
          "must_not" : [
              {"term" : {"O_LIFESTAGE" : "lymphe" }}, 
              {"term" : {"O_SEX" : "m"}}, 
              {"term" : {"L_CONTINENT" : "europe" }}, 
              {"term" : {"I_INSTITUTIONCODE" : "herbierparis"}}, 
              {"term" : {"I_INSTITUTIONCODE" : "herbiercaen"}}, 
              {"term" : {"I_INSTITUTIONCODE" : "herbiertoulouse"}}
          ]
      }
  }}'
  </code></pre>
  
  <hr>
  
  <p><strong>I can't find what i should put for the "indice" who should be my index (donnees),</strong> i even try "donnee_s". 
  Any advice are very very welcomed.
  <strong>And also if someone know who to query directly the full "myquery"</strong></p>
  
  <p>Thank you for your reading and help</p>