Spring-data-elasticsearch @CompletionField不会创建类型为“complete”的字段

cfh9epnr  于 7个月前  发布在  ElasticSearch
关注(0)|答案(1)|浏览(82)

我使用Spring-data-elasticsearchElasticsearchTemplate函数。
我尝试在名为suggestCompletion字段上使用@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文档或任何其他注解中遗漏了任何配置?

7cwmlq89

7cwmlq891#

我猜你还没有为这个实体设置一个Repository,像这样:

import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

public interface CityRepository extends ElasticsearchRepository<City, String> {

}

字符串

相关问题