我使用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
annotation应该用于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文档中,他们说,字段应该有一个类型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
文档或任何其他注解中遗漏了任何配置?
1条答案
按热度按时间7cwmlq891#
我猜你还没有为这个实体设置一个Repository,像这样:
字符串