Elasticsearch6.x和7.x的区别

Elasticsearch6.x和7.x的区别

1、查找方面的区别

在增删改方面,6.x7.x是一样的,在查找方面(分为普通查找和有高亮的查找),6.x7.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();                         
    }
}
相关推荐
洛森唛3 小时前
Elasticsearch DSL 查询语法大全:从入门到精通
后端·elasticsearch
Elasticsearch2 天前
如何使用 Agent Builder 排查 Kubernetes Pod 重启和 OOMKilled 事件
elasticsearch
Elasticsearch3 天前
通用表达式语言 ( CEL ): CEL 输入如何改进 Elastic Agent 集成中的数据收集
elasticsearch
海兰5 天前
离线合同结构化提取与检索:LangExtract + 本地DeepSeek + Elasticsearch 9.x
大数据·elasticsearch·django
yumgpkpm5 天前
AI视频生成:Wan 2.2(阿里通义万相)在华为昇腾下的部署?
人工智能·hadoop·elasticsearch·zookeeper·flink·kafka·cloudera
Sheffield5 天前
如果把ZooKeeper按字面意思比作动物园管理员……
elasticsearch·zookeeper·kafka
嗝屁小孩纸5 天前
ES索引重建(零工具纯脚本执行)
大数据·elasticsearch·搜索引擎
Elastic 中国社区官方博客5 天前
使用 Jina Embeddings v5 和 Elasticsearch 构建“与你的网站数据聊天”的 agent
大数据·人工智能·elasticsearch·搜索引擎·容器·全文检索·jina
Elastic 中国社区官方博客5 天前
Elastic 公共 roadmap 在此
大数据·elasticsearch·ai·云原生·serverless·全文检索·aws