spring-boot-starter-data-elasticsearch整合elasticsearch 6.x

2019年11月6日更新
springboot 2.2整合elasticsearch 7.x请参考
https://blog.csdn.net/chengyuqiang/article/details/102938266

1、前言

网上很多言论:

新版本的SpringBoot 2的spring-boot-starter-data-elasticsearch中支持的Elasticsearch版本是2.X,
但Elasticsearch实际上已经发展到6.5.X版本了,为了更好的使用Elasticsearch的新特性,
所以弃用了spring-boot-starter-data-elasticsearch依赖,而改为直接使用Spring-data-elasticsearch

  
  
    
    
    
    
  • 1
  • 2
  • 3

大致意思:Spring boot 2的spring-boot-starter-data-elasticsearch中支持的Elasticsearch 2.X版本,需要转向spring-data-elasticsearch,
https://github.com/spring-projects/spring-data-elasticsearch

spring data elasticsearch elasticsearch
3.2.x 6.5.0
3.1.x 6.2.2
3.0.x 5.5.0
2.1.x 2.4.0
2.0.x 2.2.0
1.3.x 1.5.2

一开始我也信了。
今天使用SpringBoot 2的spring-boot-starter-data-elasticsearch整合elasticsearch 6.x,测试了一下。实践证明是可以的。

1.1 Elasticsearch 6.x

已有5个节点的Elasticsearch 集群,版本是6.2.3。
在这里插入图片描述

2、创建SpringBoot 2.1 项目

2.1 pom.xml



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.1.RELEASE
         
    
    cn.hadron
    demo
    0.0.1-SNAPSHOT
    demo
    Demo project for Spring Boot
<properties>
    <java.version>1.8</java.version>
</properties>

<repositories>
    <repository>
        <id>nexus-aliyun</id>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59

2.2 application.properties

# ELASTICSEARCH (ElasticsearchProperties)
# Elasticsearch cluster name.
spring.data.elasticsearch.cluster-name=elasticsearch
# Comma-separated list of cluster node addresses.
spring.data.elasticsearch.cluster-nodes=192.168.12.160:9300
# Whether to enable Elasticsearch repositories.
spring.data.elasticsearch.repositories.enabled=true

 
 
   
   
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

2.3 实体类

package cn.hadron.demo.bean;

import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;

@Document(indexName = “book”, type = “_doc”)
public class BookBean {
@Id
private String id;
private String title;
private String author;
private String postDate;

public BookBean(){}

public BookBean(String id, String title, String author, String postDate){
    this.id=id;
    this.title=title;
    this.author=author;
    this.postDate=postDate;
}

public String getId() {
    return id;
}

public void setId(String id) {
    this.id = id;
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

public String getAuthor() {
    return author;
}

public void setAuthor(String author) {
    this.author = author;
}

public String getPostDate() {
    return postDate;
}

public void setPostDate(String postDate) {
    this.postDate = postDate;
}

@Override
public String toString() {
    return "BookBean{" +
            "id='" + id + '\'' +
            ", title='" + title + '\'' +
            ", author='" + author + '\'' +
            ", postDate='" + postDate + '\'' +
            '}';
}

}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65

2.4 Repository类

package cn.hadron.demo.dao;
import cn.hadron.demo.bean.BookBean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

/**

  • 接口关系:

  • ElasticsearchRepository --> ElasticsearchCrudRepository --> PagingAndSortingRepository --> CrudRepository
    */
    public interface BookRepository extends ElasticsearchRepository {

    //Optional findById(String id);

    Page findByAuthor(String author, Pageable pageable);

    Page findByTitle(String title, Pageable pageable);

}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

2.5 service层

(1)接口

package cn.hadron.demo.service;
import cn.hadron.demo.bean.BookBean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;

import java.util.List;
import java.util.Optional;

public interface BookService {

Optional<BookBean> findById(String id);

BookBean save(BookBean blog);

void delete(BookBean blog);

Optional<BookBean> findOne(String id);

List<BookBean> findAll();

Page<BookBean> findByAuthor(String author, PageRequest pageRequest);

Page<BookBean> findByTitle(String title, PageRequest pageRequest);

}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

(2)实现类

package cn.hadron.demo.service;

import cn.hadron.demo.bean.BookBean;
import cn.hadron.demo.dao.BookRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service(“blogService”)
public class BookServiceImpl implements BookService {

@Autowired
@Qualifier("bookRepository")
private BookRepository bookRepository;


@Override
public Optional<BookBean> findById(String id) {
    //CrudRepository中的方法
    return bookRepository.findById(id);
}

@Override
public BookBean save(BookBean blog) {
    return bookRepository.save(blog);
}

@Override
public void delete(BookBean blog) {
    bookRepository.delete(blog);
}

@Override
public Optional<BookBean> findOne(String id) {
    return bookRepository.findById(id);
}

@Override
public List<BookBean> findAll() {
    return (List<BookBean>) bookRepository.findAll();
}

@Override
public Page<BookBean> findByAuthor(String author, PageRequest pageRequest) {
    return bookRepository.findByAuthor(author,pageRequest);
}

@Override
public Page<BookBean> findByTitle(String title, PageRequest pageRequest) {
    return bookRepository.findByTitle(title,pageRequest);
}

}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58

2.6 控制器

package cn.hadron.demo.controller;

import cn.hadron.demo.bean.BookBean;
import cn.hadron.demo.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Optional;

@RestController
public class ElasticController {
@Autowired
private BookService bookService;

@RequestMapping("/book/{id}")
@ResponseBody
public BookBean getBookById(@PathVariable String id){
    Optional<BookBean> opt =bookService.findById(id);
    BookBean book=opt.get();
    System.out.println(book);
    return book;
}

@RequestMapping("/save")
@ResponseBody
public void Save(){
    BookBean book=new BookBean("1","ES入门教程","程裕强","2018-10-01");
    System.out.println(book);
    bookService.save(book);
}

}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

3、运行

3.1 控制台输出

"C:\Program Files\Java\jdk1.8.0_192\bin\java.exe" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=31366 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2018.3.2\lib\idea_rt.jar=31368:C:\Program Files\JetBrains\IntelliJ IDEA 2018.3.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_192\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\rt.jar;C:\Users\chengyq\IdeaProjects\demo\target\classes;C:\Users\chengyq\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.1.1.RELEASE\spring-boot-starter-web-2.1.1.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\springframework\boot\spring-boot-starter\2.1.1.RELEASE\spring-boot-starter-2.1.1.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\springframework\boot\spring-boot\2.1.1.RELEASE\spring-boot-2.1.1.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.1.1.RELEASE\spring-boot-autoconfigure-2.1.1.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.1.1.RELEASE\spring-boot-starter-logging-2.1.1.RELEASE.jar;C:\Users\chengyq\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\chengyq\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\chengyq\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.11.1\log4j-to-slf4j-2.11.1.jar;C:\Users\chengyq\.m2\repository\org\apache\logging\log4j\log4j-api\2.11.1\log4j-api-2.11.1.jar;C:\Users\chengyq\.m2\repository\org\slf4j\jul-to-slf4j\1.7.25\jul-to-slf4j-1.7.25.jar;C:\Users\chengyq\.m2\repository\javax\annotation\javax.annotation-api\1.3.2\javax.annotation-api-1.3.2.jar;C:\Users\chengyq\.m2\repository\org\yaml\snakeyaml\1.23\snakeyaml-1.23.jar;C:\Users\chengyq\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.1.1.RELEASE\spring-boot-starter-json-2.1.1.RELEASE.jar;C:\Users\chengyq\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.9.7\jackson-databind-2.9.7.jar;C:\Users\chengyq\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.9.0\jackson-annotations-2.9.0.jar;C:\Users\chengyq\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.9.7\jackson-datatype-jdk8-2.9.7.jar;C:\Users\chengyq\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.9.7\jackson-datatype-jsr310-2.9.7.jar;C:\Users\chengyq\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.9.7\jackson-module-parameter-names-2.9.7.jar;C:\Users\chengyq\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.1.1.RELEASE\spring-boot-starter-tomcat-2.1.1.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.13\tomcat-embed-core-9.0.13.jar;C:\Users\chengyq\.m2\repository\org\apache\tomcat\embed\tomcat-embed-el\9.0.13\tomcat-embed-el-9.0.13.jar;C:\Users\chengyq\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.13\tomcat-embed-websocket-9.0.13.jar;C:\Users\chengyq\.m2\repository\org\hibernate\validator\hibernate-validator\6.0.13.Final\hibernate-validator-6.0.13.Final.jar;C:\Users\chengyq\.m2\repository\javax\validation\validation-api\2.0.1.Final\validation-api-2.0.1.Final.jar;C:\Users\chengyq\.m2\repository\org\jboss\logging\jboss-logging\3.3.2.Final\jboss-logging-3.3.2.Final.jar;C:\Users\chengyq\.m2\repository\com\fasterxml\classmate\1.4.0\classmate-1.4.0.jar;C:\Users\chengyq\.m2\repository\org\springframework\spring-web\5.1.3.RELEASE\spring-web-5.1.3.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\springframework\spring-beans\5.1.3.RELEASE\spring-beans-5.1.3.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\springframework\spring-webmvc\5.1.3.RELEASE\spring-webmvc-5.1.3.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\springframework\spring-aop\5.1.3.RELEASE\spring-aop-5.1.3.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\springframework\spring-context\5.1.3.RELEASE\spring-context-5.1.3.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\springframework\spring-expression\5.1.3.RELEASE\spring-expression-5.1.3.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\springframework\boot\spring-boot-starter-thymeleaf\2.1.1.RELEASE\spring-boot-starter-thymeleaf-2.1.1.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\thymeleaf\thymeleaf-spring5\3.0.11.RELEASE\thymeleaf-spring5-3.0.11.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\thymeleaf\thymeleaf\3.0.11.RELEASE\thymeleaf-3.0.11.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\attoparser\attoparser\2.0.5.RELEASE\attoparser-2.0.5.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\unbescape\unbescape\1.1.6.RELEASE\unbescape-1.1.6.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\chengyq\.m2\repository\org\thymeleaf\extras\thymeleaf-extras-java8time\3.0.2.RELEASE\thymeleaf-extras-java8time-3.0.2.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\springframework\boot\spring-boot-starter-data-elasticsearch\2.1.1.RELEASE\spring-boot-starter-data-elasticsearch-2.1.1.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\springframework\data\spring-data-elasticsearch\3.1.3.RELEASE\spring-data-elasticsearch-3.1.3.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\springframework\spring-tx\5.1.3.RELEASE\spring-tx-5.1.3.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\springframework\data\spring-data-commons\2.1.3.RELEASE\spring-data-commons-2.1.3.RELEASE.jar;C:\Users\chengyq\.m2\repository\joda-time\joda-time\2.10.1\joda-time-2.10.1.jar;C:\Users\chengyq\.m2\repository\org\elasticsearch\client\transport\6.4.3\transport-6.4.3.jar;C:\Users\chengyq\.m2\repository\org\elasticsearch\elasticsearch\6.4.3\elasticsearch-6.4.3.jar;C:\Users\chengyq\.m2\repository\org\elasticsearch\elasticsearch-core\6.4.3\elasticsearch-core-6.4.3.jar;C:\Users\chengyq\.m2\repository\org\elasticsearch\elasticsearch-secure-sm\6.4.3\elasticsearch-secure-sm-6.4.3.jar;C:\Users\chengyq\.m2\repository\org\elasticsearch\elasticsearch-x-content\6.4.3\elasticsearch-x-content-6.4.3.jar;C:\Users\chengyq\.m2\repository\com\fasterxml\jackson\dataformat\jackson-dataformat-smile\2.9.7\jackson-dataformat-smile-2.9.7.jar;C:\Users\chengyq\.m2\repository\com\fasterxml\jackson\dataformat\jackson-dataformat-yaml\2.9.7\jackson-dataformat-yaml-2.9.7.jar;C:\Users\chengyq\.m2\repository\com\fasterxml\jackson\dataformat\jackson-dataformat-cbor\2.9.7\jackson-dataformat-cbor-2.9.7.jar;C:\Users\chengyq\.m2\repository\org\apache\lucene\lucene-core\7.4.0\lucene-core-7.4.0.jar;C:\Users\chengyq\.m2\repository\org\apache\lucene\lucene-analyzers-common\7.4.0\lucene-analyzers-common-7.4.0.jar;C:\Users\chengyq\.m2\repository\org\apache\lucene\lucene-backward-codecs\7.4.0\lucene-backward-codecs-7.4.0.jar;C:\Users\chengyq\.m2\repository\org\apache\lucene\lucene-grouping\7.4.0\lucene-grouping-7.4.0.jar;C:\Users\chengyq\.m2\repository\org\apache\lucene\lucene-highlighter\7.4.0\lucene-highlighter-7.4.0.jar;C:\Users\chengyq\.m2\repository\org\apache\lucene\lucene-join\7.4.0\lucene-join-7.4.0.jar;C:\Users\chengyq\.m2\repository\org\apache\lucene\lucene-memory\7.4.0\lucene-memory-7.4.0.jar;C:\Users\chengyq\.m2\repository\org\apache\lucene\lucene-misc\7.4.0\lucene-misc-7.4.0.jar;C:\Users\chengyq\.m2\repository\org\apache\lucene\lucene-queries\7.4.0\lucene-queries-7.4.0.jar;C:\Users\chengyq\.m2\repository\org\apache\lucene\lucene-queryparser\7.4.0\lucene-queryparser-7.4.0.jar;C:\Users\chengyq\.m2\repository\org\apache\lucene\lucene-sandbox\7.4.0\lucene-sandbox-7.4.0.jar;C:\Users\chengyq\.m2\repository\org\apache\lucene\lucene-spatial\7.4.0\lucene-spatial-7.4.0.jar;C:\Users\chengyq\.m2\repository\org\apache\lucene\lucene-spatial-extras\7.4.0\lucene-spatial-extras-7.4.0.jar;C:\Users\chengyq\.m2\repository\org\apache\lucene\lucene-spatial3d\7.4.0\lucene-spatial3d-7.4.0.jar;C:\Users\chengyq\.m2\repository\org\apache\lucene\lucene-suggest\7.4.0\lucene-suggest-7.4.0.jar;C:\Users\chengyq\.m2\repository\org\elasticsearch\elasticsearch-cli\6.4.3\elasticsearch-cli-6.4.3.jar;C:\Users\chengyq\.m2\repository\net\sf\jopt-simple\jopt-simple\5.0.2\jopt-simple-5.0.2.jar;C:\Users\chengyq\.m2\repository\com\carrotsearch\hppc\0.7.1\hppc-0.7.1.jar;C:\Users\chengyq\.m2\repository\com\tdunning\t-digest\3.2\t-digest-3.2.jar;C:\Users\chengyq\.m2\repository\org\hdrhistogram\HdrHistogram\2.1.9\HdrHistogram-2.1.9.jar;C:\Users\chengyq\.m2\repository\org\elasticsearch\jna\4.5.1\jna-4.5.1.jar;C:\Users\chengyq\.m2\repository\org\elasticsearch\plugin\reindex-client\6.4.3\reindex-client-6.4.3.jar;C:\Users\chengyq\.m2\repository\org\elasticsearch\client\elasticsearch-rest-client\6.4.3\elasticsearch-rest-client-6.4.3.jar;C:\Users\chengyq\.m2\repository\org\apache\httpcomponents\httpclient\4.5.6\httpclient-4.5.6.jar;C:\Users\chengyq\.m2\repository\org\apache\httpcomponents\httpcore\4.4.10\httpcore-4.4.10.jar;C:\Users\chengyq\.m2\repository\org\apache\httpcomponents\httpasyncclient\4.1.4\httpasyncclient-4.1.4.jar;C:\Users\chengyq\.m2\repository\org\apache\httpcomponents\httpcore-nio\4.4.10\httpcore-nio-4.4.10.jar;C:\Users\chengyq\.m2\repository\commons-codec\commons-codec\1.11\commons-codec-1.11.jar;C:\Users\chengyq\.m2\repository\org\elasticsearch\plugin\lang-mustache-client\6.4.3\lang-mustache-client-6.4.3.jar;C:\Users\chengyq\.m2\repository\com\github\spullara\mustache\java\compiler\0.9.3\compiler-0.9.3.jar;C:\Users\chengyq\.m2\repository\org\elasticsearch\plugin\percolator-client\6.4.3\percolator-client-6.4.3.jar;C:\Users\chengyq\.m2\repository\org\elasticsearch\plugin\parent-join-client\6.4.3\parent-join-client-6.4.3.jar;C:\Users\chengyq\.m2\repository\org\elasticsearch\plugin\rank-eval-client\6.4.3\rank-eval-client-6.4.3.jar;C:\Users\chengyq\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.9.7\jackson-core-2.9.7.jar;C:\Users\chengyq\.m2\repository\org\elasticsearch\plugin\transport-netty4-client\6.4.3\transport-netty4-client-6.4.3.jar;C:\Users\chengyq\.m2\repository\io\netty\netty-buffer\4.1.31.Final\netty-buffer-4.1.31.Final.jar;C:\Users\chengyq\.m2\repository\io\netty\netty-codec\4.1.31.Final\netty-codec-4.1.31.Final.jar;C:\Users\chengyq\.m2\repository\io\netty\netty-codec-http\4.1.31.Final\netty-codec-http-4.1.31.Final.jar;C:\Users\chengyq\.m2\repository\io\netty\netty-common\4.1.31.Final\netty-common-4.1.31.Final.jar;C:\Users\chengyq\.m2\repository\io\netty\netty-handler\4.1.31.Final\netty-handler-4.1.31.Final.jar;C:\Users\chengyq\.m2\repository\io\netty\netty-resolver\4.1.31.Final\netty-resolver-4.1.31.Final.jar;C:\Users\chengyq\.m2\repository\io\netty\netty-transport\4.1.31.Final\netty-transport-4.1.31.Final.jar;C:\Users\chengyq\.m2\repository\org\springframework\spring-core\5.1.3.RELEASE\spring-core-5.1.3.RELEASE.jar;C:\Users\chengyq\.m2\repository\org\springframework\spring-jcl\5.1.3.RELEASE\spring-jcl-5.1.3.RELEASE.jar" cn.hadron.demo.DemoApplication

. ____ _ __ _ _
/\ / __ _ () __ __ _ \ \ \
( ( )_
_ | '_ | '| | ’ / ` | \ \ \
\/ )| |)| | | | | || (| | ) ) ) )
’ |
| .__|| ||| |__, | / / / /
=|_|======|/=////
:: Spring Boot :: (v2.1.1.RELEASE)

2019-01-09 10:01:02.723 INFO 11456 — [ main] cn.hadron.demo.DemoApplication : Starting DemoApplication on chengyq-bg with PID 11456 (C:\Users\chengyq\IdeaProjects\demo\target\classes started by chengyq in C:\Users\chengyq\IdeaProjects\demo)
2019-01-09 10:01:02.726 INFO 11456 — [ main] cn.hadron.demo.DemoApplication : No active profile set, falling back to default profiles: default
2019-01-09 10:01:03.375 INFO 11456 — [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-01-09 10:01:03.466 INFO 11456 — [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 84ms. Found 1 repository interfaces.
2019-01-09 10:01:04.053 INFO 11456 — [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-01-09 10:01:04.074 INFO 11456 — [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-01-09 10:01:04.075 INFO 11456 — [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/9.0.13
2019-01-09 10:01:04.082 INFO 11456 — [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_192\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Tuxedo12cR2Home_1\tuxedo12.1.3.0.0_VS2010\bin;C:\Program Files (x86)\Sennheiser\SoftphoneSDK;C:\Program Files\Eisoo AnyShare;;.]
2019-01-09 10:01:04.368 INFO 11456 — [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-01-09 10:01:04.369 INFO 11456 — [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1594 ms
2019-01-09 10:01:04.748 INFO 11456 — [ main] o.elasticsearch.plugins.PluginsService : no modules loaded
2019-01-09 10:01:04.749 INFO 11456 — [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
2019-01-09 10:01:04.749 INFO 11456 — [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
2019-01-09 10:01:04.749 INFO 11456 — [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
2019-01-09 10:01:04.749 INFO 11456 — [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
2019-01-09 10:01:04.749 INFO 11456 — [ main] o.elasticsearch.plugins.PluginsService : loaded plugin [org.elasticsearch.transport.Netty4Plugin]
2019-01-09 10:01:06.120 INFO 11456 — [ main] o.s.d.e.c.TransportClientFactoryBean : Adding transport node : 192.168.12.160:9300
2019-01-09 10:01:07.283 INFO 11456 — [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService ‘applicationTaskExecutor’
2019-01-09 10:01:07.397 INFO 11456 — [ main] o.s.b.a.w.s.WelcomePageHandlerMapping : Adding welcome page template: index
2019-01-09 10:01:07.852 INFO 11456 — [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ‘’
2019-01-09 10:01:07.854 INFO 11456 — [ main] cn.hadron.demo.DemoApplication : Started DemoApplication in 5.553 seconds (JVM running for 7.149)
2019-01-09 10:01:35.487 INFO 11456 — [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet ‘dispatcherServlet’
2019-01-09 10:01:35.487 INFO 11456 — [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet ‘dispatcherServlet’
2019-01-09 10:01:35.494 INFO 11456 — [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 7 ms

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

3.2 创建文档

(1)打开浏览器,运行http://localhost:8080/save
(2)打开Kibana,
先判定book索引是否创建

HEAD book

 
 
   
   
   
   
  • 1

相应结果如下,已经创建。

200 - OK

 
 
   
   
   
   
  • 1

查看id为1的文档

GET book/_doc/1

 
 
   
   
   
   
  • 1

相应结果如下:
在这里插入图片描述

3.3 控制器查看文档1

浏览器请求:http://localhost:8080/book/1
在这里插入图片描述

                                

你可能感兴趣的:(java)