title: Spring Data ElasticSearch NullPointerException
body: <p>I have just started with Spring Data ElasticSearch. I have implemented my own repository, but I get a null pointer exception if I try to save an entity. I have got the following code, this is only some test code.</p>
  
  <pre><code>package org.test.elasticsearch.models;
  
  import org.springframework.data.annotation.Id;
  import org.springframework.data.elasticsearch.annotations.Document;
  
  @Document(indexName = "test", type = "book", shards = 1, replicas = 0)
  
  public class Book {
  
  @Id
  private String id;
  private String title;
  private String author;
  
  public Book(final String id, final String title, final String author) {
      this.id = id;
      this.title = title;
      this.author = author;
  }
  
  public String getId() {
      return this.id;
  }
  
  public void setId(final String id) {
      this.id = id;
  }
  
  public String getTitle() {
      return this.title;
  }
  
  public void setTitle(final String title) {
      this.title = title;
  }
  
  public String getAuthor() {
      return this.author;
  }
  
  public void setAuthor(final String author) {
      this.author = author;
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>package org.test.elasticsearch.configs;
  
  import org.elasticsearch.node.NodeBuilder;
  import org.test.elasticsearch.repositories.implementations.BookRepositoryImpl;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
  import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
  import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
  
  @Configuration
  @EnableElasticsearchRepositories("org.test.elasticsearch.repositories")
  public class ElasticsearchConfiguration {
  
  @Bean
  public ElasticsearchOperations elasticsearchTemplate() {
      final NodeBuilder nodeBuilder = new NodeBuilder();
      return new ElasticsearchTemplate(nodeBuilder.local(true).clusterName("elasticsearch").node().client());
  }
  
  @Bean
  public BookRepositoryImpl bookRepositoryImplementation() {
      return new BookRepositoryImpl();
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>package org.test.elasticsearch.repositories;
  
  import org.test.elasticsearch.models.Book;
  import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;
  
  public interface BookRepository extends ElasticsearchCrudRepository&lt;Book, String&gt;, BookRepositoryCustom {
  
      // query methods
  </code></pre>
  
  <p>}</p>
  
  <pre><code>package org.test.webapp;
  
  import org.test.elasticsearch.models.Book;
  import org.test.elasticsearch.models.Book.BookBuilder;
  import org.test.elasticsearch.repositories.BookRepository;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.SpringApplication;
  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  
  @Configuration
  @ComponentScan
  @EnableAutoConfiguration
  public class Test {
  
  @Autowired
  static BookRepository BookRepository;
  
  public static void main(final String[] args) {
      SpringApplication.run(test.class, args);
  
      final Book testBook = new Book("12345", "TestTitle", "TestAuthor");
      BookRepository.save(testBook);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>That's my code. And I get the following message after running my spring boot application.</p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
  at org.test.webapp.test.main(Test.java:24)
  </code></pre>
  
  <p>Does anyone have an idea? And another question: When should I use ElasticsearchTemplate with IndexQuery over a custom repository to save my entities?</p>