***************************
APPLICATION FAILED TO START
***************************

Description:

Method mvcConversionService in org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration required a bean named 'elasticsearchTemplate' that could not be found.

Action:

Consider defining a bean named 'elasticsearchTemplate' in your configuration.

查找原因 (原来以为是'elasticsearch的版本问题,后面发现了项目的问题)

一般创建的maven 产生的

application.yml的配置文件

server:
port: 19006
spring:
application:
name: essearch-service
data:
elasticsearch:
cluster-name: elasticsearch
cluster-nodes: 127.0.0.1:9300
# local: false
repositories:
enabled: true
package com.leyou.es.pojo;

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
//import org.springframework.data.elasticsearch.annotations.Document;
//import org.springframework.data.elasticsearch.annotations.Field;
//import org.springframework.data.elasticsearch.annotations.FieldType; /**
* @author :cza
* @date :2020/5/12 12:21
* @description :
* @modyified By:
*/
@Data
@Document(indexName = "heima3",type = "item",shards = 1,replicas = 0)
public class Item {
@Id
@Field(type= FieldType.Integer)
private Integer id;
@Field(type= FieldType.Text,analyzer = "ik_smart")
private String title; //标题
@Field(type= FieldType.Keyword)
private String category; //分类 @Field(type= FieldType.Keyword)
private String brand; //品牌
@Field(type= FieldType.Double)
private Double price; //价格 public Item(Integer id, String title, String category, String brand, Double price, String images) {
this.id = id;
this.title = title;
this.category = category;
this.brand = brand;
this.price = price;
this.images = images;
} public Item() {
} @Field(type= FieldType.Keyword,index = false)
private String images; //图片地址
}
package com.leyou.es.repository;

import com.leyou.es.pojo.Item;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; import java.awt.print.Pageable;
import java.util.List; /**
* @author :cza
* @date :2020/5/13 1:59
* @description :
* @modyified By:
*/
public interface ItemRepository extends ElasticsearchRepository<Item,Integer> { // List<Item> findByPriceBetween(Double begin, Double end);
// List<Item> findBypNameOrPrice(String name, Integer price);
// List<Item> findByName(String name, Pageable page);
}
package com.leyou.es;

import com.leyou.es.pojo.Item;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.Aggregations;
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.test.context.junit4.SpringRunner; import java.util.List; /**
* @author :cza
* @date :2020/5/12 12:29
* @description :
* @modyified By:
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class EsTest { @Autowired
private ElasticsearchTemplate elasticsearchTemplate;
//@Autowired
//private ItemRepository itemRepository;
//@Autowired
//private ElasticsearchRestTemplate elasticsearchRestTemplate;
@Test
public void testCreateIndex(){
//创建索引库
elasticsearchTemplate.createIndex(Item.class);
//映射关系
elasticsearchTemplate.putMapping(Item.class);
/* //创建索引库
elasticsearchRestTemplate.createIndex(Item.class);
//映射关系
elasticsearchRestTemplate.putMapping(Item.class);*/
} // /**
// * 插上全部
// */
// @Test
// public void insertIndexAll(){
// List<Item> list=new ArrayList<>();
// list.add(new Item(Integer.valueOf("1"),"坚果手机","手机","锤子",2699.00,"http://www.baidu.com"));
// list.add(new Item(Integer.valueOf("2"),"华为Mate10手机","手机","华为",3699.00,"http://www.baidu.com"));
// list.add(new Item(Integer.valueOf("3"),"小米Mi10手机","手机","小米",3099.00,"http://www.baidu.com"));
// list.add(new Item(Integer.valueOf("3"),"小米Mi8手机","手机","小米",2399.00,"http://www.baidu.com"));
//
// itemRepository.saveAll(list);
// }
//
// /**
// * 查询所有
// */
// @Test
// public void testFind(){
// Iterable<Item> all = itemRepository.findAll();
// for (Item item :all){
// System.out.println("item= "+item);
// }
// }
//
// /**
// * 根据价格查询
// */
// @Test
// public void testFindByPrice(){
// Iterable<Item> all = itemRepository.findByPriceBetween(2000d,3500d);
// for (Item item :all){
// System.out.println("item= "+item);
// }
// }
// @Test
// public void search(){
// //构建查询条件
// NativeSearchQueryBuilder queryBuilder=new NativeSearchQueryBuilder();
// //结果过滤
// queryBuilder.withSourceFilter(new FetchSourceFilter(new String[]{"id","title","price"},null));
// //添加基本分词查询
// queryBuilder.withQuery(QueryBuilders.matchQuery("title","小米"));
// //排序
// queryBuilder.withSort(SortBuilders.fieldSort("price").order(SortOrder.DESC));
// //分页
// queryBuilder.withPageable( PageRequest.of(1,20));
// Page<Item> items = this.itemRepository.search(queryBuilder.build());
// long totalcount = items.getTotalElements();
// System.out.println("totalcount="+totalcount);
// for (Item item:items){
// System.out.println(item);
// }
// List<Item> list = items.getContent();
// for (Item item :list){
// System.out.println("item="+list);
// }
// } @Test
public void testAgg(){
NativeSearchQueryBuilder queryBuilder=new NativeSearchQueryBuilder();
String aggName="popularBrand";
queryBuilder.addAggregation(AggregationBuilders.terms(aggName).field("brand"));
//查询并返回聚合结果
AggregatedPage<Item> result = elasticsearchTemplate.queryForPage(queryBuilder.build(), Item.class);
//解析聚合
Aggregations aggs = result.getAggregations(); //获取指定名称的聚合
StringTerms terms = aggs.get(aggName);
List<StringTerms.Bucket> buckets = terms.getBuckets();
for (StringTerms.Bucket bucket:buckets){
System.out.println("bucket.getKeyAsString="+bucket.getKeyAsString());
System.out.println("bucket.getDocCount="+bucket.getDocCount());
}
}
}
  <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.4.RELEASE</version>
<relativePath></relativePath>
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.SR1</spring-cloud.version>
<mapper.starter.version>2.0.3</mapper.starter.version>
</properties>
<dependencyManagement>
<dependencies>
<!--springcloud-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--通用Mapper启动器-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>${mapper.starter.version}</version>
</dependency>
<!--分页助手启动器-->
<dependency>
<groupId>com.github.pageHelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>${pageHelper.starter.version}</version>
</dependency>
<!--mysql驱动-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<!--FASTDFS客户端-->
<dependency>
<groupId>com.github.tobato</groupId>
<artifactId>fastdfs-client</artifactId>
<version>${fastDFS.client.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<!-- <version>5.0.6.RELEASE</version>-->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

es的版本下载

下载 elasticsearch 5.5.0 版本
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.zip
elasticsearch-analysis-ik 5.5.0 版本
https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.5.0/elasticsearch-analysis-ik-5.5.0.zip

查询elasticsearch-analysis-ik 版本,比如5.6.3
https://github.com/medcl/elasticsearch-analysis-ik/releases?after=v5.6.3

下载地址:https://files.cnblogs.com/files/zhian/es-demotest.zip

elasticsearchTemplate that could not be found的更多相关文章

  1. Spring ElasticsearchTemplate 经纬度按距离排序

    es实体,用 @GeoPointField 注解,值为:中间逗号隔开,如 29.477000,119.278536(经度, 维度) @Document(indexName = "v_inte ...

  2. ElasticSearch 工具类封装(基于ElasticsearchTemplate)

    1.抽象接口定义 public abstract class SearchQueryEngine<T> { @Autowired protected ElasticsearchTempla ...

  3. ElasticSearchRepository和ElasticSearchTemplate的使用

    Spring-data-elasticsearch是Spring提供的操作ElasticSearch的数据层,封装了大量的基础操作,通过它可以很方便的操作ElasticSearch的数据. 版本说明 ...

  4. elasticsearchTemplate操作es

    ElasticsearchTemplate是spring对java api的封装 maven依赖: <dependency> <groupId>org.springframew ...

  5. springboot-elasticsearch项目启动报错:'elasticsearchTemplate' that could not be found

    解决: 将elasticsearch的相关配置加入到application.yml配置文件中就可以解决

  6. elasticsearch使用操作部分

    本片文章记录了elasticsearch概念.特点.集群.插件.API使用方法. 1.elasticsearch的概念及特点.概念:elasticsearch是一个基于lucene的搜索服务器.luc ...

  7. elasticsearch spring 集成

    elasticsearch spring 集成 项目清单   elasticsearch服务下载包括其中插件和分词   http://download.csdn.net/detail/u0142011 ...

  8. Spring Data Elasticsearch

    项目清单   elasticsearch服务下载包括其中插件和分词   http://download.csdn.net/detail/u014201191/8809619   项目源码   资源文件 ...

  9. Spring Boot + Elasticsearch

    spring data elasticsearch elasticsearch 2.0.0.RELEASE 2.2.0 1.4.0.M1 1.7.3 1.3.0.RELEASE 1.5.2 1.2.0 ...

随机推荐

  1. C#关于在返回值为Task方法中使用Thread.Sleep引发的思考

    起因 最近有个小伙伴提出了一个问题,就是在使用.net core的BackgroundService的时候,对应的ExecuteAsync方法里面写如下代码,会使程序一直卡在当前方法,不会继续执行,代 ...

  2. 【Python数据分析案例】python数据分析老番茄B站数据(pandas常用基础数据分析代码)

    一.爬取老番茄B站数据 前几天开发了一个python爬虫脚本,成功爬取了B站李子柒的视频数据,共142个视频,17个字段,含: 视频标题,视频地址,视频上传时间,视频时长,是否合作视频,视频分区,弹幕 ...

  3. 【Python情感分析】用python情感分析李子柒频道视频热门评论

    一.事件背景 今天是2021.12.2日,距离李子柒断更已经4个多月了,这是我在YouTube李子柒油管频道上,观看李子柒2021年7月14日上传的最后一条视频,我录制了视频下方的来自全世界各国网友的 ...

  4. vue - Vue脚手架/消息订阅与发布

    今天的内容有意思了,朋友们继续对我们之前的案例完善,是这样的我们之前是不是靠props来完成父给子,子给父之间传数据,其实父给子最好的方法就是props但是自给父就不是了,并且今天学下来,不仅如此,组 ...

  5. scrapy架构与目录介绍、scrapy解析数据、配置相关、全站爬取cnblogs数据、存储数据、爬虫中间件、加代理、加header、集成selenium

    今日内容概要 scrapy架构和目录介绍 scrapy解析数据 setting中相关配置 全站爬取cnblgos文章 存储数据 爬虫中间件和下载中间件 加代理,加header,集成selenium 内 ...

  6. 923. 3Sum With Multiplicity - LeetCode

    Question 923. 3Sum With Multiplicity Solution 题目大意: 给一个int数组A和一个目标值target,求满足下面两个条件的组合个数,其中i,j,k分别为数 ...

  7. 设计并实现大数类 BigNum

    学习任务:设计并实现大数类 BigNum 代码示例: import java.util.Scanner; public class BigNum { private double num; publi ...

  8. falcon-eye-本机系统监控WebUI

    falcon-eye是一个简单的单机版基于WebUI的Linux系统监控工具. 安装falcon-eye root@localhost:~# mkdir falcon-eye root@localho ...

  9. 每天一个 HTTP 状态码 201

    201 Created 201 Created 表示客户端的请求已经成功完成,结果是创建了一个新资源,通常用于响应「增删改查」里的「增」.如果是严格按照 RESEful style 的 API,那么当 ...

  10. 08shell脚本

    shell脚本编程 1.1简介 什么是shell脚本 shell脚本: 就是一些命令的集合, 在脚本文件中可以有流程控制, 如顺序, 条件分支和循环等 脚本文件一般一.sh文件为扩展名, 但是不是必须 ...