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

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>cn.hadron</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
&lt;properties&gt;
    &lt;java.version&gt;1.8&lt;/java.version&gt;
&lt;/properties&gt;

&lt;repositories&gt;
    &lt;repository&gt;
        &lt;id&gt;nexus-aliyun&lt;/id&gt;
        &lt;name&gt;Nexus aliyun&lt;/name&gt;
        &lt;url&gt;http://maven.aliyun.com/nexus/content/groups/public&lt;/url&gt;
    &lt;/repository&gt;
&lt;/repositories&gt;

&lt;dependencies&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-data-elasticsearch&lt;/artifactId&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
        &lt;scope&gt;test&lt;/scope&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;

&lt;build&gt;
    &lt;plugins&gt;
        &lt;plugin&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
&lt;/build&gt;

</project>

  • 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<BookBean, String> {

    //Optional<BookBean> findById(String id);

    Page<BookBean> findByAuthor(String author, Pageable pageable);

    Page<BookBean> 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&lt;BookBean&gt; findById(String id);

BookBean save(BookBean blog);

void delete(BookBean blog);

Optional&lt;BookBean&gt; findOne(String id);

List&lt;BookBean&gt; findAll();

Page&lt;BookBean&gt; findByAuthor(String author, PageRequest pageRequest);

Page&lt;BookBean&gt; 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&lt;BookBean&gt; 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&lt;BookBean&gt; findOne(String id) {
    return bookRepository.findById(id);
}

@Override
public List&lt;BookBean&gt; findAll() {
    return (List&lt;BookBean&gt;) bookRepository.findAll();
}

@Override
public Page&lt;BookBean&gt; findByAuthor(String author, PageRequest pageRequest) {
    return bookRepository.findByAuthor(author,pageRequest);
}

@Override
public Page&lt;BookBean&gt; 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&lt;BookBean&gt; 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
在這裏插入圖片描述

                                </div>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章