ES 简介
Elasticsearch 7.x 是一个基于 Lucene 的分布式搜索引擎,它提供了一个分布式全文搜索引擎,可以快速、准确地搜索、分析和存储海量数据。Elasticsearch 7.x 的主要特点包括:
-
分布式架构:Elasticsearch 7.x 是一个分布式系统,它可以运行在多个节点上,每个节点都是相互独立的,并且数据会自动分片和复制到多个节点上,提高了系统的可用性和可扩展性。
-
实时搜索:Elasticsearch 7.x 可以快速地索引和搜索海量数据,支持实时搜索,即当数据发生变化时,可以立即搜索到最新的结果。
-
多数据类型支持:Elasticsearch 7.x 支持多种数据类型的索引和搜索,包括文本、数字、日期、地理位置等,可以满足各种不同类型数据的搜索需求。
-
分词和分析:Elasticsearch 7.x 支持文本分词和分析,它可以自动将文本分解成单词,然后进行索引和搜索,提高了搜索的准确性和效率。
-
RESTful API:Elasticsearch 7.x 提供了基于 RESTful API 的操作方式,可以通过 HTTP 请求与 Elasticsearch 进行交互,方便易用。
-
多语言支持:Elasticsearch 7.x 支持多种编程语言的客户端,包括 Java、Python、Ruby、PHP 等,可以方便地通过这些客户端进行索引和搜索操作。
-
实时监控和诊断:Elasticsearch 7.x 提供了实时监控和诊断工具,可以方便地监控集群状态、索引性能、节点状态等,提高了系统的可维护性和可靠性。
总之,Elasticsearch 7.x 是一个功能强大、性能优越、易于使用的分布式搜索引擎,可以满足各种不同规模的数据搜索和分析需求。
基本信息查询
查看所有索引
# 查看所有索引
GET _cat/indices
green open indexName1 785t4eK4SiarjIj6d_qDtA 1 0 0 0 283b 283b
green open indexName2 7WB8hk3cRMKuTUJhKWni9g 1 0 0 0 283b 283b
green open indexName3 PDJWT_VoS9iWSfEzUe5LEQ 1 0 0 0 283b 283b
green open indexName4 0qc3VwyvS9SIQ97GbILvJw 1 0 0 0 283b 283b
public Set<String> getAllIndex() {
GetAliasesRequest request = new GetAliasesRequest();
GetAliasesResponse response = null;
try {
response = restHighLevelClient.indices().getAlias(request, RequestOptions.DEFAULT);
} catch (IOException e) {
throw new RuntimeException(e);
}
Map<String, Set<AliasMetadata>> aliases = response.getAliases();
Set<String> strings = aliases.keySet();
return strings;
}
查看索引 mapping
# 查看mapping
GET indexName/_mapping
{
"indexName" : {
"mappings" : {
"properties" : {
"field1" : {
"type" : "integer"
},
"field2" : {
"type" : "keyword"
},
"field3" : {
"type" : "integer"
},
"field4" : {
"type" : "long"
},
"field5" : {
"type" : "keyword"
},
"field6" : {
"type" : "integer"
}
}
}
}
public Map<String, String> getMapping(String indexName){
GetMappingsRequest request = new GetMappingsRequest().indices(indexName);
GetMappingsResponse response = null;
try {
response = restHighLevelClient.indices().getMapping(request, RequestOptions.DEFAULT);
} catch (IOException e) {
throw new RuntimeException(e);
}
Map<String, Object> mappings = response.mappings().get(indexName).getSourceAsMap();
Map<String, Map<String, Object>> properties = (Map<String, Map<String, Object>>) mappings.get("properties");
Map<String, String> result = new HashMap<>();
properties.keySet().forEach(key -> {
String value = properties.get(key).get("type").toString();
System.out.println(key);
result.put(key, value);
} );
return result;
}
查索引中所有值
GET indexName/_search
{
"query":{
"match_all": {
}
}
}
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
}

本文介绍了Elasticsearch7.x的核心特性,如分布式架构、实时搜索和多数据类型支持。接着详细讲解了如何进行基本信息查询,包括查看所有索引、获取索引mapping以及搜索索引中的所有值。此外,还阐述了过滤、模糊查询和去重的方法,如bool查询、wildcard查询以及聚合去重策略。
最低0.47元/天 解锁文章

8908

被折叠的 条评论
为什么被折叠?



