构建Filter

使用过滤器可以提高查询速度

  1. private ElasticsearchTemplate elasticsearchTemplate;
  2. SearchQuery searchQuery = new NativeSearchQueryBuilder()
  3. .withQuery(matchAllQuery())
  4. .withFilter(boolFilter().must(termFilter("id", documentId)))
  5. .build();
  6. Page<SampleEntity> sampleEntities =
  7. elasticsearchTemplate.queryForPage(searchQuery,SampleEntity.class);