我正在使用
我尝试通过在名为
在elasticsearch文档中,他们说,为了使用suggest-complete函数,该字段应该具有类型
但是,如果我不小心创建我的索引,那么字段
Spring-data-elasticsearch
和 ElasticsearchTemplate
函数。我尝试通过在名为
suggest
的Completion
字段上使用@CompletionField
注释来创建索引。@Document(indexName = "city", type = "city")
public class City {
@Id
private String id;
@Field
private String name;
@CompletionField
private Completion suggest;
}
@CompletionField
注解应该用于elasticsearch的建议完成功能。如java-doc中所述:
/**
* Based on the reference doc - http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-suggesters-completion.html
*
* @author Mewes Kochheim
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
@Inherited
public @interface CompletionField {
在elasticsearch文档中,他们说,为了使用suggest-complete函数,该字段应该具有类型
complete
。但是,如果我不小心创建我的索引,那么字段
suggest
的类型不是complete
,而是keyword
。这会在尝试查询建议查询时导致错误。CompletionSuggestionBuilder s = SuggestBuilders.completionSuggestion("suggest").prefix(text, Fuzziness.ONE);
SuggestBuilder b = new SuggestBuilder().addSuggestion("test-suggest", s);
SearchResponse response = elasticsearchTemplate.suggest(b, "city");
异常:
java.lang.IllegalArgumentException: no mapping found for field [suggest]
我的所有代码都基于spring-data-elasticsearch git存储库。
ElasticsearchTemplateCompletionTests.java
CompletionAnnotatedEntity.java
我在City
文档或其他注释中是否错过了任何配置?