Reputation: 85
im running a query on ES but the number of params are increasing (due to business reasons).
According to the doc in spring data elastic search you can use @Query
with ordered parameters like ?0
, ?1
and so on for parameters given in the signature of the method but this approach seems a bit uncomfortable
Is it possible to make a query like :#{#myParam.myPropOfMyParam}
in other words use SpEL to access argument properties?
and not end with a method with a bunch of parameters like
@Query("match.... ?0,.. ?1, ?2")
Page<Doc> findBy(String arg1, String arg2, String arg3, Pageable pageable)
and to be more like spring-data-jpa uses
public interface CompanyDocRepo extends ElasticsearchRepository<CompanyDoc, UUID> {
@Query(value =
"{\n" +
" \"multi_match\": {\n" +
" \"query\": \"#{#keyword['somevalue']}\",\n" +
" \"fields\": [\n" +
" \"name\",\n" +
" \"description\",\n" +
" \"city\",\n" +
" \"department\",\n" +
" \"sectors.sector.descriptionSector\",\n" +
" \"sectors.sector.description\",\n" +
" \"sectors.sector.name\",\n" +
" \"interests.name\"\n" +
" ]\n" +
" }\n" +
"}\n")
Page<CompanyDoc> findByKeyword(@Param("keyword") Map<String,String> keyword, Pageable pageable);
}
or if there are other ways to make a query without leave a side spring data interfaces?
Upvotes: 1
Views: 452
Reputation: 19471
This is currently not possible. You might want to create an issue for this at https://github.com/spring-projects/spring-data-elasticsearch/issues
Upvotes: 0