<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. android——字符串string(转)

    原文地址:http://www.open-open.com/lib/view/open1387942832078.html String : 字符串类型 一.构造函数     String(byte[ ...

  2. SQL SERVER 事务和锁

    内容皆整理自网络 一.事务 作者:郭无心链接:https://www.zhihu.com/question/31346392/answer/59815366来源:知乎著作权归作者所有.商业转载请联系作 ...

  3. iis7.5 发布mvc出错的解决办法

    发布mvc,配置iis7.5时,遇到这个错误. xxxx'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b ...

  4. 移动端报表JS开发演示样例

    近期对移动端的报表开发颇有研究,细磨精算了好久,尽管到如今还是"囊中羞涩",但决定还是先抛砖引玉,拿点小干货出来和大家分享. 研究的工具是比較有代表性的FineReport. 1. ...

  5. ffmpeg 将jpg转为yuv

    ffmpeg -i temp.jpg -s 1024x680 -pix_fmt yuvj420p 9.yuv   此前网上有条盛传的命令 -y -s出来uv是错的

  6. float right

    很多时候,"更多"会和title在一行显示,放在右边 我们可能马上想到这样做: h1 a{ float: right; } <h1>这是个title<a>更 ...

  7. R语言常用基础知识(入门)

    data.frame 动态确定列名称 var <- "mpg" #Doesn't work mtcars$var #These both work, but note tha ...

  8. 关于Unity中坐标系的种类

    坐标空间 1:物体空间: 3D物体自己的坐标空间 一般设计时几何体以中心为原点,人物以双脚为原点; 2: 世界空间: 3D物体在场景中的世界坐标, 整个游戏场景的空间; 3: 摄像机空间: 以观察摄像 ...

  9. VMware Fusion 5 正式版序列号

    HV4KJ-2X10K-VZ768-DRAGP-8CU2F MY63N-D0HE2-0ZXC1-HV954-937JL

  10. Ogre 监听类与渲染流程

    Ogre中有许多监听类,我们可以简单理解成C#中的事件,这些类作用都不小,说大点可能改变流程,说小点修改参数等,下面列举一些常用的监听类. FrameListener:由Ogre中的Root负责维护, ...