Search code examples
spring-bootelasticsearchspring-data-elasticsearch

spring-data-elasticsearch search template


We have a few similar queries and I wanted to do some templating based on parameters. Recently I've found that elastic supports search templates so I'm wondering whether this is supported by spring-data-elasticearch.

Currently my query looks something like:

final Query query = new NativeSearchQueryBuilder().addAggregation(aggregationBuilder)
      .withPageable(EmptyPage.INSTANCE)
      .withQuery(queryBuilder)
      .build();

I'm wondering if I can somehow pass the template that I've stored in application and get the result from elastic. Or if I can store the template in elastic and get the result based on parameters.


Solution

  • No, Spring Data Elasticsearch currently does not support search templates.

    Edit 16.03.2021: search template support has been added to the ReactiveElasticsearchClientin Spring Data Elasticsearch by a pull request from bilak. Thanks for that.