这里下载的是elasticsearch2.4.4的版本html
elasticsearch-head-masterjava
下载地址https://github.com/mobz/elasticsearch-headnode
修改下图文件git
双击以下图batgithub
http://192.168.2.104:9200/_plugin/head/,192.168.2.104是刚才在配置文件配置的本机ipspring
也能够直接生成win服务app
maven添加以下jar包elasticsearch
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
<version>1.5.1.RELEASE</version>
</dependency>
增长一个es的配置文件
@Configuration @EnableElasticsearchRepositories(basePackages = "com.example.demo.dao") public class EsConfig { @Value("${elasticsearch.host}") private String EsHost; @Value("${elasticsearch.port}") private int EsPort; @Value("${elasticsearch.clustername}") private String EsClusterName; @Bean public Client client() throws Exception { Settings esSettings = Settings.settingsBuilder() .put("cluster.name", EsClusterName) .build(); //https://www.elastic.co/guide/en/elasticsearch/guide/current/_transport_client_versus_node_client.html return TransportClient.builder() .settings(esSettings) .build() .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(EsHost), EsPort)); } @Bean public ElasticsearchOperations elasticsearchTemplate() throws Exception { return new ElasticsearchTemplate(client()); }
这个必须和es配置文件里面是对应的否则会报错,端口号默认也是这个。maven
下面是配置对应的索引和类型ide
下面建立一个接口扩展es的JPA,这里实现了基本的增删改查
public interface UzaiProductRepository extends ElasticsearchRepository<EsProduct, String> { EsProduct save(EsProduct esProduct); /* * * @author: wangchao * @date: 2017/9/22 * @methodName: 分页取数据 * @param null * @return */ Page<EsProduct> findByLocationName(String locationName, Pageable pageable); }
下面是经过id实现了一个简单的查询
@GetMapping("/search") public ResponseEntity<EsProduct> getSearch(@RequestParam("id") String id) { EsProduct esProduct=uzaiProductService.findOne(id); return new ResponseEntity<EsProduct>(esProduct, HttpStatus.OK); }
到此基本spring boot下实现了es的curd