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
# 旧版本以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
# 新版本以spring.elasticsearch.rest.开头;访问地址配置需要声明访问协议,直接监听es访问端口
spring.elasticsearch.rest.uris=http://localhost:9200
3、Document注解的type属性
es6.x 有type = “_doc”
@Document(indexName = "discusspost", type = "_doc", shards = 6, replicas = 3)
public class DiscussPost {
}
es7.x 无type = “_doc”
@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文章来源:https://www.toymoban.com/news/detail-646708.html
@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文章来源地址https://www.toymoban.com/news/detail-646708.html
@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();
}
}
到了这里,关于Elasticsearch6.x和7.x的区别的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!