The latest elasticsearch7 (five combined mybatis, springboot instance)

Foreword

Previous introduce Elasticsearch7.5 crack method, the results do not support csdn now somehow cracked, activation class Bowen public, the audit did not pass. But the Internet also has other versions of the hack, the new version will distinguish some of the details that are needed can also leave a message behind.
This section we followed the third quarter to write down examples of Elasticsearch combined mybatis. maven dependence x-pack-sql-jdbcneed to add, but also remember to configure repository, because the central warehouse not released.

DataSource Configuration

@Configuration
@MapperScan(basePackages={"com.yds.datacenter.dao.es"}, sqlSessionFactoryRef="esSqlSessionFactory")
public class ElasticsearchConfig {

    @Bean(name = "esDataSource")
    public DataSource clickHouseDataSource() {
        EsDataSource dataSource = new EsDataSource();
        String address = "jdbc:es://192.168.9.226:9200";
        dataSource.setUrl(address);
        Properties connectionProperties = new Properties();
        dataSource.setProperties(connectionProperties);
        return dataSource;
    }

    @Bean(name = "esSqlSessionFactory")
    public SqlSessionFactory clickHouseSqlSessionFactory(@Qualifier("esDataSource") DataSource esDateSource) throws Exception {
        final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
        sessionFactory.setDataSource(esDateSource);
        sessionFactory.setConfigLocation(new ClassPathResource("mybatis-config.xml"));
        return sessionFactory.getObject();
    }
}

mybatis script

    <select id="query" parameterType="java.lang.String" resultType="com.tt.datacenter.utils.es.Person">
        ${param1}
    </select>

    <select id="count" resultType="java.lang.Long">
        select count(*) from person
    </select>

unit test

I'm here to insert the test data index named Person 100 million, and total use sql query, then query a random set of data condition, avoid caching effects. You can see the total number of more than 134 million, we randomly query time is 328 milliseconds.

Here Insert Picture Description
ES7 combined configuration mybatis configuration is very simple to use query is not very convenient.

Published 62 original articles · won praise 33 · views 130 000 +

Guess you like

Origin blog.csdn.net/yyoc97/article/details/104270018