这里下载的是elasticsearch2.4.4的版本
elasticsearch-head-master
下载地址https://github.com/mobz/elasticsearch-head

修改下图文件


双击如下图bat

http://192.168.2.104:9200/_plugin/head/,192.168.2.104是刚才在配置文件配置的本机ip

也可以直接生成win服务


maven添加如下jar包
<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配置文件里面是对应的不然会报错,端口号默认也是这个。
下面是配置对应的索引和类型

下面创建一个接口扩展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
elasticsearch在spring boot项目下的应用
原文:http://www.cnblogs.com/ok123/p/7527701.html