Pat*_*ick 6 java elasticsearch spring-boot spring-data-elasticsearch
我正在使用Spring-data-elasticsearch并且有ElasticsearchTemplate功能。
我尝试通过@CompletionField在Completion名为的字段上使用注释来创建索引suggest。
@Document(indexName = "city", type = "city")
public class City {
@Id
private String id;
@Field
private String name;
@CompletionField
private Completion suggest;
}
Run Code Online (Sandbox Code Playgroud)
该@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 {
Run Code Online (Sandbox Code Playgroud)
在他们说的elasticsearch 文档中,该字段应该有一个类型complete来使用建议完成功能。
但是,如果我不幸地创建索引,该字段suggest没有 typecomplete而是它具有 type keyword。当我尝试查询建议查询时,这给了我一个错误。
CompletionSuggestionBuilder s = SuggestBuilders.completionSuggestion("suggest").prefix(text, Fuzziness.ONE);
SuggestBuilder b = new SuggestBuilder().addSuggestion("test-suggest", s);
SearchResponse response = elasticsearchTemplate.suggest(b, "city");
Run Code Online (Sandbox Code Playgroud)
例外:
java.lang.IllegalArgumentException: no mapping found for field [suggest]
Run Code Online (Sandbox Code Playgroud)
我所有的代码都基于 spring-data-elasticsearch git 存储库。
ElasticsearchTemplateCompletionTests.java
CompletionAnnotatedEntity.java
我是否遗漏了City文档或任何其他注释中的任何配置?
小智 0
我猜您还没有为此实体设置存储库,如下所示:
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
public interface CityRepository extends ElasticsearchRepository<City, String> {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
936 次 |
| 最近记录: |