spring-data-elasticsearch-2.0.4.RELEASE startsWith 不适用于非分析字段
spring-data-elasticsearch-2.0.4.RELEASE startsWith doesn't work with non analyzed field
我正在使用 ElasticserachRepoistory,以下查询不适用于未分析的字符串:
findByNameStartingWithIgnoreCase(字符串名称);
如果我对字段进行分析,它会作用于字符串中的每个单词而不是短语的开头。
使用非分析字段实现此目的的最简单方法是什么?我需要它来自动完成
我已经完成了自定义分析器并且它有效:
@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;
}
json 文件:
{
"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"
]
}
}
}
}
}
我正在使用 ElasticserachRepoistory,以下查询不适用于未分析的字符串: findByNameStartingWithIgnoreCase(字符串名称);
如果我对字段进行分析,它会作用于字符串中的每个单词而不是短语的开头。
使用非分析字段实现此目的的最简单方法是什么?我需要它来自动完成
我已经完成了自定义分析器并且它有效:
@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;
}
json 文件:
{
"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"
]
}
}
}
}
}