elasticsearchspring-dataspring-data-elasticsearchelasticsearch-2.0

spring-data-elasticsearch-2.0.4.RELEASE startsWith doesn't work with non analyzed field


I'm using ElasticserachRepoistory and the following query doesn't work with non analyzed string : findByNameStartingWithIgnoreCase(String name);

if I make the field analyzed it works on each word inside the string instead of the start of the phrase.

what is the easiest way to achieve this with non analyzed field ? I need it for auto complete


Solution

  • I have done custom analyzer and it worked :

    @Document(indexName = "db", type = "user")
    @Getter
    @Setter
    @Setting(settingPath = "/settings.json")
    public class User{
    
    
        @org.springframework.data.annotation.Id
        private Long id;
    
        @Field(analyzer= "autocomplete",type = FieldType.String )
        private String name;
    
        }
    

    the json file :

       { 
    "index": {
    "number_of_shards": 1,
    "analysis": {
      "filter": {
        "autocomplete_filter": {
          "type": "edge_ngram",
          "min_gram": 1,
          "max_gram": 20
        }
      },
      "analyzer": {
        "autocomplete": {
          "type": "custom",
          "tokenizer": "keyword",
          "filter": [
            "lowercase",
            "autocomplete_filter"
          ]
         }
        }
       } 
      }
    }