96SEO 2026-02-19 22:58 0
。

其主要目标是使得对数据的访问变得方便快捷#xff0c;并支持
是一个用于简化数据库、非关系型数据库、索引库访问并支持云服务的开源框架。
其主要目标是使得对数据的访问变得方便快捷并支持
JPA的写法可以在几乎不用写实现的情况下实现对数据的访问和操作。
除了
的官网https://spring.io/projects/spring-data/
https://spring.io/projects/spring-data-elasticsearch
Boot版本https://docs.spring.io/spring-data/elasticsearch/docs/4.3.0/reference/html/#preface.requirements
xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.3.6.RELEASE/versionrelativePath//parentgroupIdorg.example/groupIdartifactIdspringdata-elasticsearch/artifactIdversion1.0-SNAPSHOT/versionpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.targetproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependenciesdependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-data-elasticsearch/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-devtools/artifactIdscoperuntime/scopeoptionaltrue/optional/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-test/artifactId/dependencydependencygroupIdjunit/groupIdartifactIdjunit/artifactId/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-test/artifactId/dependency/dependencies
增加配置文件application.properties添加以下配置
logging.level.com.atguigu.esdebug5
启动类SpringDataElasticSearchMainApplication
SpringDataElasticSearchMainApplication
{SpringApplication.run(SpringDataElasticSearchMainApplication.class,args);}
客户端的。
需要自定义配置类继承AbstractElasticsearchConfiguration并实现elasticsearchClient()抽象方法创建
AbstractElasticsearchConfiguration
newRestHighLevelClient(builder);return
ElasticsearchRepositoryProduct,Long
ElasticsearchRestTemplateAutowiredprivate
elasticsearchRestTemplate;//创建索引并增加映射配置Testpublic
createIndex(){//创建索引系统初始化会自动创建索引System.out.println(创建索引);}Testpublic
deleteIndex(){//创建索引系统初始化会自动创建索引boolean
elasticsearchRestTemplate.deleteIndex(Product.class);System.out.println(删除索引
Product();product.setId(1L);product.setTitle(华为手机);product.setCategory(手机);product.setPrice(2999.0);product.setImages(http://www.atguigu/hw.jpg);productDao.save(product);}//修改Testpublic
Product();product.setId(1L);product.setTitle(小米
手机);product.setCategory(手机);product.setPrice(9999.0);product.setImages(http://www.atguigu/xm.jpg);productDao.save(product);}//根据
productDao.findById(1L).get();System.out.println(product);}Testpublic
{System.out.println(product);}}//删除Testpublic
Product();product.setId(1L);productDao.delete(product);}//批量新增Testpublic
Product();product.setId(Long.valueOf(i));product.setTitle([
]小米手机);product.setCategory(手机);product.setPrice(1999.0
i);product.setImages(http://www.atguigu/xm.jpg);productList.add(product);}productDao.saveAll(productList);}//分页查询Testpublic
productDao.findAll(pageRequest);for
{System.out.println(Product);}}
执行delete()删除id为1的数据后再执行findAll()方法查找索引的所有文档查看程序执行结果
执行saveAll()方法批量新增后执行findByPageable方法分页查询数据查看程序执行结果
在测试文档查询之前需要先配置中文分词器ElasticSearch默认的内置分词器standard是针对英文等拉丁语系设计的是不支持中文分词的。
IK分词器是一个开源的中文分词器插件丰富和优化了Elasticsearch
环境ES7.8安装ik分词器为例对应下载ik分词器7.8版本下载链接https://release.infinilabs.com/analysis-ik/stable/elasticsearch-analysis-ik-7.8.0.zip
ik分词器各个版本的下载链接https://release.infinilabs.com/analysis-ik/stable/
GitHub仓库链接https://github.com/infinilabs/analysis-ik
从上面的分词结果可以看到查询“小米手机”就查不到了。
这时候就需要我们自定义拆分文本
首先在plugins\ik\config目录下新建一个文本文件命名为.dic后缀的文件例如我命名为myWord.dic
。
开自定义的dic文件在其中编写你需要的词语这里要将文件的编码选择为UTF-8否则无法正确识别
打开plugins\ik\config目录下的IKAnalyzer.cfg.xml文件将自定义的dic文件写入
productDao.search(termQueryBuilder);for
{System.out.println(product);}}/***
productDao.search(termQueryBuilder,
{System.out.println(product);}}
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback