注意事项见代码注释:
package com.ddao.es.test;
import com.ddao.es.entity.Article;
import com.ddao.es.repositories.ArticleRrpository;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.QueryStringQueryBuilder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@SuppressWarnings("ALL")
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:applicationContext.xml")
public class Testes {
@Autowired
private ArticleRrpository articleRrpository;
@Autowired
private ElasticsearchTemplate template;
@Test
public void testes(){
template.createIndex(Article.class);
//配置mapping映射关系
//template.putMapping(Article.class);
}
@Test