title: How to search elastic search via Java using ElasticsearchRepository?
body: <p>I'm creating a Java application using Elastic Search.
  Here is the link for my project.
  <a href="https://github.com/chanakaDe/ensembl-elastic-rest" rel="nofollow noreferrer">https://github.com/chanakaDe/ensembl-elastic-rest</a></p>
  
  <p>In this project, I have implemented a rest controller to take data as JSON.
  This is the controller class. Now it only has 2 methods. But I need to add some method like this.</p>
  
  <pre><code>@RequestMapping(value = "/find-by/{id}/{param1}/{param2}/{param3}", method = RequestMethod.GET)
  public Iterable&lt;Track&gt; findAllWithParams(@PathVariable int id, @PathVariable String param1, @PathVariable String param2, @PathVariable String param3) {
      return trackService.someMethodWithParams(id, param1, param2, param3);
  }
  </code></pre>
  
  <p>What I need to do is take some values from user and send them into Elastic server and make a search. I just refered some of these links and got some idea.
  <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search.html</a>
  <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html</a></p>
  
  <p>TrackService.java and TrackServiceImpl.java are implemented by TrackRepository.java and it's extended by ElasticsearchRepository default class. <a href="https://github.com/chanakaDe/ensembl-elastic-rest/blob/master/src/main/java/com/chanaka/book/repository/TrackRepository.java" rel="nofollow noreferrer">https://github.com/chanakaDe/ensembl-elastic-rest/blob/master/src/main/java/com/chanaka/book/repository/TrackRepository.java</a></p>
  
  <p>I need to take values via REST URL and create an object like following and pass that to Elastic Server. How can I implement that with my current project configuration ? </p>
  
  <pre><code>{
  "query": {
      "constant_score" : {
          "filter" : {
              "terms" : { "user" : ["kimchy", "elasticsearch"]}
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This is my TrackService.java interface.</p>
  
  <pre><code>public interface TrackService {
  
  Track save(Track track);
  
  Track findOne(int id);
  
  Iterable&lt;Track&gt; findAll();
  </code></pre>
  
  <p>}</p>
  
  <p>And also this is my TrackServiceImpl.java class implemented by TrackService.java.</p>
  
  <pre><code>public class TrackServiceImpl implements TrackService {
  
  private TrackRepository trackRepository;
  
  @Autowired
  public void setTrackRepository(TrackRepository trackRepository) {this.trackRepository = trackRepository;}
  
  @Override
  public Track save(Track track) {
      return trackRepository.save(track);
  }
  
  @Override
  public Track findOne(int id) {
      return trackRepository.findOne(id + "");
  }
  
  @Override
  public Iterable&lt;Track&gt; findAll() {
      return trackRepository.findAll();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Do I need to implement a custom method for that ? Or is there any default methods like findAll() and findOne() ? 
  Simply pass an object and get the value ?</p>