title: Partial match with Spring Data Elasticsearch
body: <p>I was able to search by whole words, for example searching phrase "secret" text "This is a secret word" was found. But If I search for phrase "secre" I get an empty array. I need this for autocomplete function. I'm using Spring Boot release 1.3.1.RELEASE (it uses Elasticsearch version 1.5.2 and I can't upgrade spring). What am I doing wrong? I'l be thankful for a link to a working example also. I know Elasticsearch is too heavy for this purpose but I want to learn how to use it. Many thanks in advance!</p>
  
  <p><strong>SearchConfig.java</strong></p>
  
  <pre><code>@Configuration
  @EnableElasticsearchRepositories(basePackages = {"cz.project.search"})
  public class SearchConfig {
  
      @Autowired
      private Client elasticsearchClient;
  
      @Bean
      public ConstructionWorkIndexInitializer constructionWorkIndexInitializer() {
          return new ConstructionWorkIndexInitializer();
      }
  }
  </code></pre>
  
  <p><strong>ConstructionWorkIndexRepository.java</strong></p>
  
  <pre><code>public interface ConstructionWorkIndexRepository extends ElasticsearchRepository&lt;ConstructionWorkIndex, String&gt; {
          Page&lt;ConstructionWorkIndex&gt; findByCodeOrDescription(String code, String description, Pageable pageable);
  }
  </code></pre>
  
  <p><strong>ConstructionWorkIndex.java</strong></p>
  
  <pre><code>@Data
  @AllArgsConstructor
  @NoArgsConstructor
  @Document(indexName = "works", type = "work", shards = 1, replicas = 0, indexStoreType = "memory", refreshInterval = "-1")
  @Setting(settingPath = "classpath:construction-works-settings.json")
  public class ConstructionWorkIndex {
  
      @Id
      @Field(indexAnalyzer = "standard", searchAnalyzer = "standard", type = FieldType.String, store = true)
      private String code;
  
      @Field(indexAnalyzer = "standard", searchAnalyzer = "standard", type = FieldType.String, store = true)
      private String description;
  
      public ConstructionWorkIndex(ConstructionWorkVO constructionWork) {
          requireNonNull(constructionWork, "constructionWork must not be null");
          this.code = constructionWork.getCode();
          this.description = constructionWork.getDescription();
      }
  }
  </code></pre>
  
  <p><strong>construction-works-settings.json</strong></p>
  
  <pre><code>{
    "filter": {
      "autocomplete_filter": {
        "type": "edge_ngram",
        "min_gram": 1,
        "max_gram": 20
      }
    },
    "analyzer": {
      "autocomplete": {
        "type": "custom",
        "tokenizer": "standard",
        "filter": [
          "lowercase",
          "autocomplete_filter"
        ]
      }
    }
  }
  </code></pre>
  
  <p><strong>ConstructionWorkIndexInitializer.java</strong></p>
  
  <pre><code>@Slf4j
  public class ConstructionWorkIndexInitializer {
  
      @Autowired
      private ConstructionWorkRepository workRepository;
  
      @Autowired
      private ConstructionWorkIndexRepository workIndexRepository;
  
      @PostConstruct
      @Transactional(readOnly = true)
      @Async
      public void init() {
          initWorks();
      }
  
      private void initWorks() {
          List&lt;ConstructionWorkVO&gt; works = workRepository.findAll();
          works.forEach(work -&gt; {
              workIndexRepository.save(new ConstructionWorkIndex(work));
              log.debug("Added construction work code '{}'", work.getCode());
          });
          log.debug("Indexed {} construction works", works.size());
      }
  }
  </code></pre>