Elasticsearch6.x和7.x的区别

Elasticsearch6.x和7.x的区别

1、查找方面的区别

在增删改方面,6.x和7.x是一样的,在查找方面(分为普通查找和有高亮的查找),6.x和7.x有区别。

在7.x的es中:

  • org.springframework.data.elasticsearch.core.SearchResultMapper没有这个类了

  • org.springframework.data.elasticsearch.core.ElasticsearchTemplate 已废弃

  • org.springframework.data.elasticsearch.repository.ElasticsearchRepository<T,

​ ID>.search(org.springframework.data.elasticsearch.core.query.Query) 已废弃

于是在普通查找和带高亮的查找方面,es6.x和7.x不一样。

2、配置文件的区别

es6.x application.properties

properties 复制代码
# 旧版本以spring.data.elasticsearch.开头;访问地址配置不用声明访问协议,监听es的tcp端口
# 7.x已经弃用了
spring.data.elasticsearch.cluster-name=my-application
spring.data.elasticsearch.cluster-nodes=127.0.0.1:9300

es7.x application.properties

properties 复制代码
# 新版本以spring.elasticsearch.rest.开头;访问地址配置需要声明访问协议,直接监听es访问端口
spring.elasticsearch.rest.uris=http://localhost:9200

3、Document注解的type属性

es6.x 有type = "_doc"

java 复制代码
@Document(indexName = "discusspost", type = "_doc", shards = 6, replicas = 3)
public class DiscussPost {

}

es7.x 无type = "_doc"

java 复制代码
@Document(indexName = "discusspost", shards = 6, replicas = 3)
public class DiscussPost {

}

4、Elasticsearch Clients的区别

下方内容来自官方文档:

https://docs.spring.io/spring-data/elasticsearch/docs/4.0.1.RELEASE/reference/html/#reference

ES6.x:Transport Client

java 复制代码
@Configuration
public class TransportClientConfig extends ElasticsearchConfigurationSupport {

    @Bean
    public Client elasticsearchClient() throws UnknownHostException {
        Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();        
        TransportClient client = new PreBuiltTransportClient(settings);
        client.addTransportAddress(new TransportAddress(InetAddress.getByName("127.0.0.1"), 9300)); 
        return client;
    }

    @Bean(name = { "elasticsearchOperations", "elasticsearchTemplate" })
    public ElasticsearchTemplate elasticsearchTemplate() throws UnknownHostException {
        return new ElasticsearchTemplate(elasticsearchClient());
    }
}

ES7.x:High Level REST Client

java 复制代码
@Configuration
public class RestClientConfig extends AbstractElasticsearchConfiguration {

    @Override
    @Bean
    public RestHighLevelClient elasticsearchClient() {

        final ClientConfiguration clientConfiguration = ClientConfiguration.builder()  
            .connectedTo("localhost:9200")
            .build();

        return RestClients.create(clientConfiguration).rest();                         
    }
}
相关推荐
Flynn Liang8 小时前
内存/Redis/PGVector/Milvus/ES 怎么选?Spring AI VectorStore 抽象与向量库选型对照表
redis·elasticsearch·milvus·rag·springai·pgvector·向量库
Elastic 中国社区官方博客17 小时前
基于 Jina OCR v1 与 Elasticsearch 的 PDF 智能混合检索与 RAG 系统实战指南
大数据·数据库·elasticsearch·搜索引擎·ocr·jina
Eloudy1 天前
Qwen2.5-14B-Instruct-AWQ 模型文件结构分析
大数据·elasticsearch·搜索引擎
YIN_尹1 天前
【git原理与使用】git初识与安装
大数据·git·elasticsearch
Elastic 中国社区官方博客2 天前
Elastic 在《Forrester Wave™:2026 年第四季度智能运维平台》报告中被评为强劲表现者
大数据·运维·数据库·elasticsearch·搜索引擎·全文检索
Elasticsearch2 天前
Elastic Cloud 无服务器服务审计日志:将审计记录发送到可观测性或安全解决方案
elasticsearch
zwjapple2 天前
skill总结
大数据·elasticsearch·搜索引擎
阿里云大数据AI技术2 天前
云栖实录|从代码上下文到千亿级文档:Qoder × 阿里云 Elasticsearch 落地生产级Agent向量检索
人工智能·elasticsearch
Elastic 中国社区官方博客3 天前
使用 OpenTelemetry 在 Elastic 中实现 Claude 平台的人工智能 agent 可观测性
大数据·运维·服务器·人工智能·elasticsearch·信息可视化·全文检索
Elastic 中国社区官方博客4 天前
Elastic 重大事件功能如何将 100 条日志样本转化为检测规则
大数据·运维·数据库·人工智能·elasticsearch·搜索引擎