title: Bean method 'elasticsearchTemplate' not able to find in configuration
body: <p>Getting Below Error:</p>
  <hr />
  <p>APPLICATION FAILED TO START</p>
  <hr />
  <p>Description:</p>
  <pre><code>Field template in com.rahul.es.api.service.QueryDSLService required a bean of type 'org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate' that could not be found.
  
  The injection point has the following annotations:
      - @org.springframework.beans.factory.annotation.Autowired(required=true)
  
  The following candidates were found but could not be injected:
      - Bean method 'elasticsearchTemplate' in 'ElasticsearchDataConfiguration.RestClientConfiguration' not loaded because @ConditionalOnMissingBean (names: elasticsearchTemplate types: org.springframework.data.elasticsearch.core.ElasticsearchOperations; SearchStrategy: all) found beans of type 'org.springframework.data.elasticsearch.core.ElasticsearchOperations' elasticsearchTemplate and found beans named elasticsearchTemplate
  
  
  Action:
  
  Consider revisiting the entries above or defining a bean of type 'org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate' in your configuration.
  </code></pre>
  <p><strong>EsConfig.java</strong></p>
  <pre><code>@Configuration(proxyBeanMethods=false)
  @EnableElasticsearchRepositories(basePackages = &quot;com.rahul.es.api.repository&quot;)
  @ComponentScan(basePackages = { &quot;com.rahul.es.api.service&quot; })
  public class EsConfig {
  
      @Bean
      public RestHighLevelClient client() {
          ClientConfiguration clientConfiguration 
              = ClientConfiguration.builder()
                  .connectedTo(&quot;localhost:9200&quot;)
                  .build();
   
          return RestClients.create(clientConfiguration).rest();
      }
   
      @Bean
      public ElasticsearchOperations elasticsearchTemplate() {
          return new ElasticsearchRestTemplate(client());
      }
  }
  </code></pre>
  <p><strong>QueryDSLService</strong></p>
  <pre><code>@Service
  public class QueryDSLService {
  
      @Autowired
      private ElasticsearchRestTemplate template;
  
      public List&lt;Customer&gt; searchMultipleField(String firstname, int age) {
  
          QueryBuilder query = QueryBuilders.boolQuery().must(QueryBuilders.matchQuery(&quot;firstname&quot;, firstname))
                  .must(QueryBuilders.matchQuery(&quot;age&quot;, age));
  
          NativeSearchQuery nativeSearchQuery = new NativeSearchQueryBuilder().withQuery(query).build();
          List&lt;Customer&gt; customers = template.queryForList(nativeSearchQuery, Customer.class);
          return customers;
      }
  
      public List&lt;Customer&gt; getCustomerSearchData(String input) {
          String search = &quot;.*&quot; + input + &quot;.*&quot;;
          SearchQuery searchQuery = new NativeSearchQueryBuilder()
                  .withFilter(QueryBuilders.regexpQuery(&quot;firstname&quot;, search)).build();
          List&lt;Customer&gt; customers = template.queryForList(searchQuery, Customer.class);
          return customers;
      }
  
      public List&lt;Customer&gt; multiMatchQuery(String text) {
          SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(QueryBuilders.multiMatchQuery(text)
                  .field(&quot;firstname&quot;).field(&quot;lastname&quot;).type(MultiMatchQueryBuilder.Type.BEST_FIELDS)).build();
          List&lt;Customer&gt; customers = template.queryForList(searchQuery, Customer.class);
          return customers;
  
      }
  
  }
  </code></pre>
  <p><strong>RestController</strong></p>
  <pre><code>@SpringBootApplication
  @RestController
  public class SpringbootElasticsearchQuerydslApplication {
      
      @Autowired
      private QueryDSLService service;
  
      @GetMapping(&quot;/serachMultiField/{firstname}/{age}&quot;)
      public List&lt;Customer&gt; serachByMultiField(@PathVariable String firstname, @PathVariable int age) {
          return service.searchMultipleField(firstname, age);
      }
  
      @GetMapping(&quot;/customSearch/{firstName}&quot;)
      public List&lt;Customer&gt; getCustomerByField(@PathVariable String firstName) {
          return service.getCustomerSearchData(firstName);
      }
  
      
      /**Based on wildcard method */
      @GetMapping(&quot;/search/{text}&quot;)
      public List&lt;Customer&gt; doMultimatchQuery(@PathVariable String text) {
          return service.multiMatchQuery(text);
      }
  
      public static void main(String[] args) {
          SpringApplication.run(SpringbootElasticsearchQuerydslApplication.class, args);
      }
  
  }
  </code></pre>