Spring-data-elasticsearch @CompletionField does not create field with type "complete"
Asked Answered
E

1

7

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?

Exegete answered 27/2, 2018 at 12:46 Comment(0)
M
0

I guess you haven't set up a Repository for this entity, like this:

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

public interface CityRepository extends ElasticsearchRepository<City, String> {

}
Minimalist answered 23/10, 2023 at 8:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.