项目中进行整合:

1、整合 新建项目加入依赖(NoSql)

springboot默认使用SpringDate ElasticSearch模块进行操作
 
查看自动配置类:

SpringBoot默认支持两种技术来和ES交互“
1、Jest

2、SpringDate ElasticSearch
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQYAAAAXCAYAAADpyOG2AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAVPSURBVHhe7VtLbxxFEOYfYTlS4hxyADuwiXnIjpFgIYmiAMmBaBcJhCWSi2XAcEHKYYPCQ+RgbQ4ocAFZawnxz5qu7qmZ6urqnund8Xoj1eGT3dVd1fXqb3omzisbF9cMYHt721y7elmhUCiMEoNCoYigxKBQKCIoMSgUighKDAqFIsJixHD9NfPm/Qfm6sMfzNY3PznA7yCDOVFHoVCsPOYmhsFwaDYtEWx+/6sMOwdrJN02DLbumSezx2a8tSHOl2IwfGSms2NzOOzHXt/w8a6uf31hsLVjDqczc3p6aiZfP1yJmiyzN/ru67PEXMTgSOFIIAMOuyZFDrRJELMqaUoM0hqfr9nknjjfJ7w/TW362vPWwXFta1VqosQgo5gYBvYVIXtT4ICbg/BagY3+ZBQnadEE5myvIjoRAzTw9Ng2cfe8zJOHweixIwOqA7LpwU6wbh6MJ7Ne7CyC8+yN8yCGj+9/Ym7sXgtkMAY5lXEUEwN8PwgO/tEv5tLdsVnb3jPrb79v1m/cDOct3DcHZkeJoUEXYoCnLRwqOFxd4yrNg/fj7PKmxLB8YkASQHLg4xSKiQE+LtJDv3H3c3Nh76Z5/dv0LQJ0uJ0SYvDXveZqS3XgwNRXXqsz2vzUNXctmz4yH30A77PEXnUAcA02K7fVtt7NJXxr4vO64Mcta0+y5WWWGA780xpAr+/elicOeHqjrWZ/nis5D9L+QZzMtoSsvhAH5gpIgeqMMjWZVTZqnxMxwjiZZ6Euke92bVtvdI2Pg9tp6szjCH1E/VQvpuQ5IBkMP9zrRAqAYmLgrxGvvvGuubJ/FMgiWB1uBwuKQbpA8f2TJNCtm5CDAM2Lc6xhuO36kAaN5AvGC5q2VTVD9TSntrO+VevixhL2ruSp9296YCN/mN9hrCwPwv6Bzy3E0KrfEge9MYR+er3Gzyp3BcQQ5rm9Ll17oyS+Wkew08iJH6V9nZB3AZIC/JTmOXoghnfMla++C2QRMsSABQrnmgSiTGLKulCsONniJ5o/acuup+SFoEWXfYvjy+9NDrvTlQ8UH/NmCWLleRD2p2tS/tVr2/QL4mirCZWVxEjRpS6tfhTEV+sk8uj1mzgAZX0ty9uwlBsDf5W4eOeBWd+VXyWe/jkzL07+M0//+CeykysoTaAvXPog+PXeFiastPgUka3M+pxvUnz5hmmK7XUxFt8M2DxRE7F85HxINz7dq/GDo1SfzsF4WcTg57vVpdWPgvhqHcGOkzv9aq+Mj81672tMELJcApICkgEfp9DDx8efzaU7I7N2fdesvfWeubB328l3fnzmSGH/9xfuJ7fDCxTOkQSyJAPD0kNxiAUm9rjtsDHANpmz40NbnLStcD1gPOngmxBfcm8nlxvO7RE1TGPHx9bo5nxAPWxGJxNjYI1o14BOm34uDhgv9irRLUanX1AXyY954qM+xvHQOld75Xy0tsReTMhhnIJEAkgOVMZRTAwl/1wJhABrc8QQPgVpYsNC4pqpPZSUWaHZan3ywQ4S7WQ2+dEHJldEr0cPXcoWXQ9oCp72LVU4ae9cw4FP1BcElWOs3Ac6FzY3iZOsRUDT4rxbQ3OR0c/FAeMUMTRjzIvVIR8fYT4Vo5TnXF2oLbE35ozP+0/mknUO/cZ9uvZ1St43iokB0OUPnKZ//+sIAfH8rxPRlkIhgT9RFcvFXMQAaPuTaCSEL/e/qH+X7CgU/ukZP7XplV6xXMxNDA6Z/0SFZDAef6bEoGgFvXoDlBTOF4sRQwbw6oCEANBXCYXi5cGZEYNCoXh5ERDD5m8nCoVCocSgUCg4Tsz/YxXmqPH/OdUAAAAASUVORK5CYII=" alt="" />
@Bean
@ConditionalOnMissingBean
public TransportClient elasticsearchClient() throws Exception {
TransportClientFactoryBean factory = new TransportClientFactoryBean();
factory.setClusterNodes(this.properties.getClusterNodes());
factory.setProperties(this.createProperties());
factory.afterPropertiesSet();
return factory.getObject();
} private Properties createProperties() {
Properties properties = new Properties();
properties.put("cluster.name", this.properties.getClusterName());
properties.putAll(this.properties.getProperties());
return properties;
}

public class ElasticsearchProperties {
private String clusterName = "elasticsearch";
private String clusterNodes;
private Map<String, String> properties = new HashMap();

@Bean
@ConditionalOnMissingBean
@ConditionalOnBean({Client.class})
public ElasticsearchTemplate elasticsearchTemplate(Client client, ElasticsearchConverter converter) {
try {
return new ElasticsearchTemplate(client, converter);
} catch (Exception var4) {
throw new IllegalStateException(var4);
}
}

2、测试

1、Jest方式

依赖:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency> <!-- https://mvnrepository.com/artifact/io.searchbox/jest -->
<dependency>
<groupId>io.searchbox</groupId>
<artifactId>jest</artifactId>
<version>5.3.</version>
</dependency>

@Bean(
destroyMethod = "shutdownClient"
)
@ConditionalOnMissingBean
public JestClient jestClient() {
JestClientFactory factory = new JestClientFactory();
factory.setHttpClientConfig(this.createHttpClientConfig());
return factory.getObject();
}
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAK4AAAAiCAYAAADGfuJNAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAR0SURBVHhe7ZpLTxNRFID7j0SIPARU+sACvniYaEUMwddCQk00soCNQUU3RhZgEI0utC4MutFgSYz/7DjnTs/Mmdsz0xaZttOexZfOfZ77+ObOjJgaPZeGXH4STvadguEz52Dk7FhH023z7URwD1Nj2ZzZwP6hYbFSp9Ft8+1EcA9T6dw4nBo83SWn7Rh003w7EdrDFCaGRs6IlTqNs+ms+e2W+XYitIdGXEVJGiqukkhUXCWRpKampkBRkkZqsL8HCMyYyA0pSstBF6WTllBxlbZExVUSiYqrJBIVV0kkKq6SSOIXd3IMzt9fhtz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W+ml3VNzmE6u4hoj/ZEOyFosPVFylIeIXNwJ8NSBhkaS+KijNp6XiKspRaVjczIcDRWk5Kq6SSGqKixU4UieK0mxsL21S8/NpUJRkkYZ/muWR6FH3EyMAAAAASUVORK5CYII=" alt="" />相关的配置
private List<String> uris = new ArrayList(Collections.singletonList("http://localhost:9200"));
 
配置文件:
spring.elasticsearch.jest.uris=http://192.168.1.121:9200

pojo类:

public class Article {
//标识为主键
//@JestId

private Integer id;
private String author;
private String title;
}

测试类:

@Autowired
JestClient jestClient; @Test
public void contextLoads() {
System.out.println(jestClient);
//给es保存索引文档
Article article = new Article();
article.setId();
article.setAuthor("mrchengs");
article.setTitle("EsTest"); String id = String.valueOf(article.getId());
//构建一个索引功能
//new Index.Builder(article).index("cr").type("msg").id()
//cr是索引 msg是类型 此时也是可以是设置id的,但是在类中已经进行了设置
Index index = new Index.Builder(article).index("cr").type("msg").id(id).build(); try {
jestClient.execute(index);
} catch (IOException e) {
e.printStackTrace();
} }
此时的可以查看结果:

测试搜索功能的实现:

{"took":,"timed_out":false,"_shards":{"total":,"successful":,"skipped":,"failed":},"hits":{"total":,"max_score":0.2876821,"hits":[{"_index":"cr","_type":"msg","_id":"","_score":0.2876821,"_source":{"id":,"author":"mrchengs","title":"EsTest"}}]}}

 2、SpringDate ElasticSearch

待更新.......

30、springboot与检索(2)的更多相关文章

  1. java框架之SpringBoot(13)-检索及整合Elasticsearch

    ElasticSearch介绍 简介 我们的应用经常需要使用检索功能,开源的 Elasticsearch 是目前全文搜索引擎的首选.它可以快速的存储.搜索和分析海量数据.SpringBoot 通过整合 ...

  2. 29、springboot与检索(1)

    一.检索 我们的应用经常需要添加检索功能,开源的 ElasticSearch 是目前全文搜索引擎的首选. 他可以快速的存储.搜索和分析海量数据.Spring Boot通过整合Spring Data E ...

  3. springboot 注册dao层 service 层

    可以使用三种注解来引入DAO层的接口到spring容器中.1.@Mapper,写在每一个DAO层接口上,如下: 2.@MapperScan和@ComponentScan两者之一.前者的意义是将指定包中 ...

  4. 千锋很火的SpringBoot实战开发教程视频

    springboot是什么? Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员 ...

  5. ElasticSearch+Springboot实际应用:索引同步建设,搜索过程

    1.介绍 springboot框架,众多自动化的部署和约定配置,造成了springboot的着手麻烦,熟练后可以快速快捷进行开发,常用作快捷开发的java底层框架.各位看官都是大神,自行体会.     ...

  6. SpringBoot集成MyBatis的分页插件 PageHelper

    首先说说MyBatis框架的PageHelper插件吧,它是一个非常好用的分页插件,通常我们的项目中如果集成了MyBatis的话,几乎都会用到它,因为分页的业务逻辑说复杂也不复杂,但是有插件我们何乐而 ...

  7. springboot 知识点

    ---恢复内容开始--- 1springBoot项目引入方式, 1,继承自父 project (需要没有付项目才能用,一般我们的项目都会有 父 项目 所以 这种方式不推荐 ,记住有这种方式 就可以了) ...

  8. 微服务springboot视频最新SpringBoot2.0.3版本技术视频教程【免费学习】

    超火爆的springboot微服务技术怎么学,看这里,springboot超详细的教程↓↓↓↓↓↓https://ke.qq.com/course/179440?tuin=9b386640 01.sp ...

  9. SpringBoot Redis 实践指南

    前言 SpringBoot Cache 是一个很好的缓存框架,可以兼容多种缓存实现,数据量较大的情况下,Redis 应该是最多被使用的. 本文重点介绍 SpringBoot 和 Redis 整合使用的 ...

随机推荐

  1. Autocomplete 自动提示

    <!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  2. jsp技术知识点

    1.jsp被Tomcat翻译成.java文件后,会被放在Tomcat安装目录下的\work\Catalina\localhost\station\org\apache\jsp文件夹下 2.El表达式表 ...

  3. 浅析Java 8新功能Optional

    初识 A container object which may or may not contain a non-null value. 笔者理解,Optional是一个容器类.将Object放到Op ...

  4. 领域模型(DomainModel)与视图模型(ViewModel)

    Model-View-Controller(模型-视图-控制器,MVC)模式将你的软件组织并分解成三个截然不同的角色: Model 封装了你的应用数据.应用流程和业务逻辑. View 从 Model ...

  5. Code Signal_练习题_alternatingSums

    Several people are standing in a row and need to be divided into two teams. The first person goes in ...

  6. HtmlEntities

    #region GetOnlyTextFromHtmlCode + RemoveHtmlChars + RemoveTagFromHtmlCode /// <summary> /// ht ...

  7. attr()与prop()之全选、反选问题

    获取js dom原生属性的时候最好用prop()方法,获取自己添加的属性时用attr() 原文:http://blog.sina.com.cn/s/blog_bf5ce8cc0102vuyt.html ...

  8. synchronized修饰普通方法,修饰静态方法,修饰代码块,修饰线程run方法 比较

    synchronized用于多线程设计,有了synchronized关键字,多线程程序的运行结果将变得可以控制.synchronized关键字用于保护共享数据. synchronized实现同步的机制 ...

  9. 购物车redis存储结构

  10. mvn install 时候报GBK编码错误解决办法

    在pom.xml里面 <properties> <!-- 文件拷贝时的编码 --> <project.build.sourceEncoding>UTF-</p ...