Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

All methods in the `ElasticsearchRepository` are deprecated. What should do I use?

I have this query:

NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
                .withQuery(multiMatchQuery(searchPattern)
                        .field("fullName")
                        .field("npi")
                        .type(MultiMatchQueryBuilder.Type.BEST_FIELDS))
                .build();

How can I run it? All methods in the ElasticsearchRepository are deprecated:

public interface ElasticsearchRepository<T, ID> extends PagingAndSortingRepository<T, ID> {
    /** @deprecated */
    @Deprecated
    default <S extends T> S index(S entity) {
        return this.save(entity);
    }

    /** @deprecated */
    @Deprecated
    <S extends T> S indexWithoutRefresh(S var1);

    /** @deprecated */
    Iterable<T> search(QueryBuilder var1);

    /** @deprecated */
    Page<T> search(QueryBuilder var1, Pageable var2);

    /** @deprecated */
    Page<T> search(Query var1);

    Page<T> searchSimilar(T var1, @Nullable String[] var2, Pageable var3);

    /** @deprecated */
    @Deprecated
    void refresh();
}
like image 237
Pavel Petrashov Avatar asked Oct 30 '25 02:10

Pavel Petrashov


1 Answers

The Javadoc for the deprecated methods states that you should

  • either define the queries by using the standard method name derivation like findByName
  • or use the @Query annotation wit a query string
  • or don not use the repository interface but the ElasticsearchOperations to pass your custom Query derived queries.

We deprecated the methods from the repository interface that use the Queryclasses. Not only in Spring Data Elasticsearch, but we do not intorduce them in other modules as well; see the comment on this Spring Data Mongo issue for more information.

like image 184
P.J.Meisch Avatar answered Oct 31 '25 20:10

P.J.Meisch