<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>
<groupId>elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>0.0.1-SNAPSHOT</version> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>3.0.9</version>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build>
<resources>
<resource>
<directory>src/main/resources/${build.profile.id}</directory>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<!-- spring boot maven插件,可以将项目打包成一个可执行的jar文件 -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<!-- 该配置使devtools生效 -->
<fork>true</fork>
</configuration>
</plugin>
</plugins>
<finalName>newtouch-ms-platform</finalName>
</build> </project>

pom.xml

 spring.data.elasticsearch.cluster-name=elasticsearch
spring.data.elasticsearch.cluster-nodes=170.20.1.115:9200
spring.data.elasticsearch.repositories.enable=true

application.properties

package com.newtouch.elasticsearch.elasticsearch.repository;

import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Component; import com.newtouch.elasticsearch.elasticsearch.document.BookDocument;
@Component
public interface BookSearchRepository extends ElasticsearchRepository<BookDocument, Long>{ }
package com.newtouch.elasticsearch.elasticsearch.document;

import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document; @Document(indexName ="megacorp",type = "book", shards = 1,replicas = 0, refreshInterval = "-1")
public class BookDocument { @Id
private int id; private String name; private String title; private String auther; public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuther() {
return auther;
}
public void setAuther(String auther) {
this.auther = auther;
} }
 @Persistent
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface Document { String indexName();//索引库的名称,个人建议以项目的名称命名 String type() default "";//类型,个人建议以实体的名称命名 short shards() default 5;//默认分区数 short replicas() default 1;//每个分区默认的备份数 String refreshInterval() default "1s";//刷新间隔 String indexStoreType() default "fs";//索引文件存储类型
}

@Document注解

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@Documented
@Inherited
public @interface Field { FieldType type() default FieldType.Auto;#自动检测属性的类型 FieldIndex index() default FieldIndex.analyzed;#默认情况下分词 DateFormat format() default DateFormat.none; String pattern() default ""; boolean store() default false;#默认情况下不存储原文 String searchAnalyzer() default "";#指定字段搜索时使用的分词器 String indexAnalyzer() default "";#指定字段建立索引时指定的分词器 String[] ignoreFields() default {};#如果某个字段需要被忽略 boolean includeInParent() default false;
}

@Field注解

可以参考:http://www.tianshouzhi.com/api/tutorials/elasticsearch/159

springboot+elasticsearch配置实现的更多相关文章

  1. springboot elasticsearch 集成注意事项

    文章来源: http://www.cnblogs.com/guozp/p/8686904.html 一 elasticsearch基础 这里假设各位已经简单了解过elasticsearch,并不对es ...

  2. SpringBoot实战之SpringBoot自动配置原理

    SpringBoot 自动配置主要通过 @EnableAutoConfiguration, @Conditional, @EnableConfigurationProperties 或者 @Confi ...

  3. Springboot 自动配置浅析

    Introduction 我们知道,SpringBoot之所以强大,就是因为他提供了各种默认的配置,可以让我们在集成各个组件的时候从各种各样的配置文件中解放出来. 拿一个最普通的 web 项目举例.我 ...

  4. springboot集成elk 一: springboot + Elasticsearch

    1.ELK介绍 1> Elasticsearch是实时全文搜索和分析引擎, 提供搜集.分析.存储数据三大功能: 是一套开放REST和JAVA API等结构提供高效搜索功能,可扩展的分布式系统. ...

  5. SpringBoot自动配置探究

    @SpringBootApplication @SpringBootApplication表示SpringBoot应用,标注在某个类上说明这个类是SpringBoot的主配置类,SpringBoot就 ...

  6. 浅谈springboot自动配置原理

    前言 springboot自动配置关键在于@SpringBootApplication注解,启动类之所以作为项目启动的入口,也是因为该注解,下面浅谈下这个注解的作用和实现原理 @SpringBootA ...

  7. SpringBoot常用配置简介

    SpringBoot常用配置简介 1. SpringBoot中几个常用的配置的简单介绍 一个简单的Spring.factories # Bootstrap components org.springf ...

  8. ElasticSearch 配置详解

    配置文件位于es根目录的config目录下面,有elasticsearch.yml和logging.yml两个配置,主配置文件是elasticsearch.yml,日志配置文件是logging.yml ...

  9. Elasticsearch 配置

    Elasticsearch 配置 Elasticsearch不仅仅是Lucene和全文搜索,我们还能这样去描述它: 分布式的实时文件存储,每个字段都被索引并可被搜索 分布式的实时分析搜索引擎 可以扩展 ...

随机推荐

  1. python 全局变量的使用

    我尝试使用 类似 C 语言的方式去调用 python 的全局变量,发现不行,后经过 尝试,要使用 global 进行调用 test_num = 0; # 首先声明一个全局变量 def test_fun ...

  2. Tomcat性能优化(三) Executor配置

    http://hello-nick-xu.iteye.com/blog/2113853 http://blog.chinaunix.net/uid-12115233-id-3358004.html

  3. Java8中list转map

    第一种: 取list中某2个字段作为Map的K,V public Map<Long, String> getIdNameMap(List<Account> accounts) ...

  4. 【嵌入式】——arm裸机开发 step by step 之 串口通信

    一.在使用S5PV210的串口发送和接收的时候,首先要对S5PV210的串口进行配置,我们使用轮询方式时的配置有哪些? 1.配置GPIO,使对应管脚作为串口的发送和接收管脚 GPA0 0 1 管脚 2 ...

  5. gitlab安装与配置(Centos6.8)

    0.Centos7请参照官方文档 https://about.gitlab.com/installation/#centos-7 1. Install and configure the necess ...

  6. android studio 解析Excel数据格式导入poi-3.17.jar时的一系列报错及处理Failed resolution of: Ljavax/xml/stream/XMLEventFactory,duplicate entry: org/apache/xmlbeans/xml/stream/Location.class,GC overhead limit exceeded

    在org官网下载的poi jar包,导入到studio compile files('libs/poi-3.17.jar') compile files('libs/poi-ooxml-3.17.ja ...

  7. 关于Unity点击New创建新项目没反应的解决方案

    1.登出Unity 2.再登录Unity 3.再次点击New,可以

  8. Ubuntu下Ruby的下载和编译源码安装

    1.Ruby的下载 Ruby可以在Ruby 官网上下载,如果想获取更多的Ruby版本,可以到淘宝镜像网站下载. 2.Ruby的编译源码安装 解压 首先把下载下来的源码压缩包解压到自己指定的目录 编译安 ...

  9. SAP的战略企业管理功能介绍

    目         录 1.        总述 2.        SAP SEM- 战略管理 3.        SAP SEM- 绩效测评 4.        SAP SEM- 业务合并 5.  ...

  10. 第一个shell程序

    前言:我为什么又来学习shell呢?因为这个轻量级的编程小脚本语言能够帮我处理一些基于linux的复杂手工工作.真是一言难尽,学会一门又来一门!! 看了2天这个教程,试着写了一个小脚本,没啥技术含量, ...