Es dynamic index query


Run-time setting index

Configuration file

Configure bean

    String indexName;

    public String indexName(){
        return indexName;

Configure domain

@Document(indexName="#{@indexName}", type = "log")


public interface DemoDao extends ElasticsearchRepository<Demo,String>{
    Page<Demo> findByApp(String app, Pageable pageable);

The advantage is that the runtime can specify, but cannot dynamically query different index’s

dynamic parameter

    ElasticsearchTemplate elasticsearchTemplate;
    public void demo(String index,String type,String app,Pageable page){
        MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("app",app);
        SearchQuery query = new NativeSearchQueryBuilder()
        Page<Demo> data = elasticsearchTemplate.queryForPage(query,Demo.class);