<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. vs2010中TargetName与链接器输出名不一致

    当出现解决方案生成正确,但是无法执行.exe文件,即系统无法找到指定文件时,提示有:MSB8012: TargetName(,,,) 与 Linker 的 OutputFile 属性(,,,)不匹配. ...

  2. UK 更新惊魂记

    本文前提是.由于更easy安装各种webserver.数据库,redis缓存.mq等软件,笔者使用Ubuntu Kylin作为开发系统已经好长时间了. 而今天(2015-07-23)下午2时许,系统提 ...

  3. Redis基准

    Redis的基准是实用程序运行n个命令检查Redis 的性能. 语法 redis的基准的基本语法如下所示: redis-benchmark [option] [option value] 例子 下面给 ...

  4. 解决:No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency

    错误: Description: Field jdbcTemplate in com.gwd.dao.impl.IUserDaoImpl required a bean of type 'org.sp ...

  5. PCL深度图像(1)

    目前深度图像的获取方法有激光雷达深度成像法,计算机立体视觉成像,坐标测量机法,莫尔条纹法,结构光法等等,针对深度图像的研究重点主要集中在以下几个方面,深度图像的分割技术 ,深度图像的边缘检测技术 ,基 ...

  6. MATLAB — axis

    转至:http://blog.csdn.net/cs_zlg/article/details/8516463 axis中文为“轴”之意,在matlab中用于控制坐标轴的范围和样式(颜色等). axis ...

  7. Entity Framework Code First - Change Tracking

    In this post we will be discussing about change tracking feature of Entity Framework Code First. Cha ...

  8. CodeCombat森林关卡Python代码

    地牢关卡过完,接下来是边缘的森林! 1,森林保卫战 hero.moveUp() hero.buildXY("fence", 40, 52) hero.moveDown() hero ...

  9. python写的读取json配置文件

    配置文件默认为conf.json 使用函数set完成追回配置项. 使用load或取配置项. 代码如下: #!/usr/bin/env python3 # -*- coding: utf-8 -*- ' ...

  10. windows系统的便签

    习惯了使用便签,但是重装系统时,一个一个备份太麻烦. win7便笺保存在C:\Users\你的用户名\AppData\Roaming\Microsoft\Sticky Notes\下.重装前拷贝出来, ...