I am using Spring-data-elasticsearch
and there ElasticsearchTemplate
functions.
I try to create an index by using the @CompletionField
annotation on a Completion
field named suggest
.
@Document(indexName = "city", type = "city")
public class City {
@Id
private String id;
@Field
private String name;
@CompletionField
private Completion suggest;
}
The @CompletionField
annotation should be used to for the suggest-complete functions of elasticsearch. Like described in the 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 {
In the elasticsearch docs they say, that the field should have a type complete
to use the suggest-complete functions.
But if I create my index unfortunately the field suggest
has not the type complete
instead it hast the type keyword
. Which gives me an error when I try to query a suggest query.
CompletionSuggestionBuilder s = SuggestBuilders.completionSuggestion("suggest").prefix(text, Fuzziness.ONE);
SuggestBuilder b = new SuggestBuilder().addSuggestion("test-suggest", s);
SearchResponse response = elasticsearchTemplate.suggest(b, "city");
Exception:
java.lang.IllegalArgumentException: no mapping found for field [suggest]
All my code is based on the spring-data-elasticsearch git repository.
ElasticsearchTemplateCompletionTests.java
CompletionAnnotatedEntity.java
Do I miss any configuration in my City
document or any other annotation?