title: how to write code for search in elasticsearch using jest client in java
body: <p>I try this code URL is <a href="http://localhost:9200" rel="nofollow">http://localhost:9200</a> index is restaurant type is menu.
  I want pass id through the <code>searchbuilder</code>. Please anyone can help me. I got this output</p>
  
  <pre><code>722 [main] INFO io.searchbox.client.JestClientFactory - Node Discovery       Disabled...
  hai 
  io.searchbox.core.SearchResult@35f8a538
  </code></pre>
  
  <p>but I want id data</p>
  
  <pre><code>import io.searchbox.client.JestClient;
  import io.searchbox.client.JestClientFactory;
  import io.searchbox.client.JestResult;
  import io.searchbox.client.config.HttpClientConfig;
  import io.searchbox.core.Search;
  import io.searchbox.core.SearchResult;
  import io.searchbox.core.SearchResult.Hit;
  
  import java.io.IOException;
  import java.sql.Date;
  import java.util.ArrayList;
  import java.util.Calendar;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Map;
  import java.util.UUID;
  
  import jesttask.*;
  
  import org.elasticsearch.index.query.QueryBuilders;
  import org.elasticsearch.search.SearchHit;
  import org.elasticsearch.search.builder.SearchSourceBuilder;
  
  import com.google.gson.JsonObject;
  
  public class Elasticsearch 
  {
  public static void main( String[] args ) throws Exception 
  {
      JestClient client = openClient();
  
      JsonObject json=new JsonObject();
  </code></pre>
  
  <p>for search code here</p>
  
  <pre><code>   /* Search search = (Search) new Search.Builder("http://localhost:9200/")
      // multiple index or types can be added.
      .addIndex("articles")
      .addType("article")
      .build();
  
  JestResult result = client.execute(search);*/
  
      SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
      searchSourceBuilder.query(QueryBuilders.queryString("AVE5MpaA7X6GJDWpFptT"));
      Search search = (Search) new Search.Builder(searchSourceBuilder.toString())
                                      // multiple index or types can be added.
                                      .addIndex("restarent")
                                      .addType("menu")
                                      .build();
      System.out.println("hai");
      JestResult result = client.execute(search);
      System.out.println(result);
  
  
      List&lt;SearchModel&gt; reviewList = result.getSourceAsObjectList(SearchModel.class);
      for(SearchModel review: reviewList){
          System.out.println("h");
        System.out.println("search result is " + review);
      }
  
      /*
      SearchHit[] results = result.getHits().getHits();
      for (SearchHit hit : results) {
        System.out.println(hit.getId());    //prints out the id of the document
        Map&lt;String,Object&gt; result2 = hit.getSource();   //the retrieved document
      }*/
  
      /*List&lt;SearchModel&gt; sources = result.getSourceAsObjectList(SearchModel.class);
  
      for (SearchModel source : sources) {
          System.out.println("h");
  
          System.out.println(source.getTitle() + " -&gt; " + source.getItem());
      }*/
  
      client.shutdownClient();
  }
  
  private static JestClient openClient()
  { 
   HttpClientConfig clientConfig = new HttpClientConfig.Builder("http://localhost:9200/")
        .multiThreaded(true).build();
   JestClientFactory factory = new JestClientFactory();
  
   factory.setHttpClientConfig(clientConfig);
   JestClient jestClient = factory.getObject();
  
   return jestClient;
  }
  }
  </code></pre>
  
  <p>my model class is</p>
  
  <pre><code>import io.searchbox.annotations.JestId;
  
  import com.fasterxml.jackson.annotation.JsonProperty;
  
  public class SearchModel {
  @JestId
  private String id;
  
  @JsonProperty("price")
  private double price;
  @JsonProperty("quantity")
  private String quantity;
  
  @JsonProperty("item")
  private String item;
  
  
  
  
  public String getId() {
      return id;
  }
  public void setId(String id) {
      this.id = id;
  }
  public double getPrice() {
      return price;
  }
  public void setPrice(Double price) {
      this.price = price;
  }
  
  public String getQuantity() {
      return quantity;
  }
  public void setQuantity(String quantity) {
      this.quantity = quantity;
  }
  
  public String getItem() {
      return item;
  }
  public void setItem(String item) {
      this.item = item;
  }
  
  
  }
  </code></pre>