美文网首页媴媴知识
Elasticsearch 入门(二)

Elasticsearch 入门(二)

作者: 尼罗河上的小杀手 | 来源:发表于2017-09-13 11:02 被阅读41次

零、Basic Concept

  • ES存储方式
    它是面向文档的(Document oriented),它存储整个对象或文档,并且索引每个文档的内容,使之可以被检索。Elasticsearch使用JSON作为文档的序列化格式。

  • ES索引
    关系型数据库通过增加一个索引,比如一个B-树 索引到指定的列上,以便提升数据检索速度。Elasticsearch 和lucene使用了一个叫排序索引的结构达到相同的目的。

  • ES文档
    Elasticsearch中文档(Document)是指最顶层或者根对象 这个根对象被序列化成 JSON 并存储到 Elasticsearch 中,指定了唯一 ID。文档包含它的数据以及它的元数据(文档本身信息)。
    文档三个必须的元数据:_index, _type, _id 即文档存在哪儿,文档的类型,文档唯一标识符。

  • ES VS 关系型数据库
    Elasticsearch的 index --> DB ,
    Elasticsearch的type --> table,
    Elasticsearch的Document -->对应table的一行记录row,
    Document的Field --> table里面的column

“Relational DB -> Databases -> Tables -> Rows -> Columns
Elasticsearch -> Indices -> Types -> Documents -> Fields”

一、Elasticsearch 搜索初识

  • 搜索accounts的下所有post
$ curl -XGET 'localhost:9200/accounts/post/_search?pretty'
  • 搜索accounts下特定的post
$ curl -XGET 'localhost:9200/accounts/post/_search?q=tag:elasticsearch'
  • 使用DSL(Domain Specific Language)查询,ES有一些高级查询包括 aggregation,短语搜索,跟SQL 中group by ,like 等类似。当然还有逼格更高的模糊查询,匹配度之类的。
curl -XGET 'localhost:9200/megacorp/employee/_search?pretty' -H 'Content-Type: application/json' -d'
{
    "query" : {
        "match" : {
            "tag" : "elasticsearch"
        }
    }
}
'

二、分布式(cluster, node, shared)

  • 一个节点(node),就是一个Elasticsearch实例,集群(cluster)由一个或多个节点组成,节点有相同的cluster.name。当新加入或者删除节点时,集群会感知并平衡数据。

  • 一个分片(shared)是一个最小级别 worker unit。文档存储在分片中,然后分配到集群的节点上。分片分为primary shared 和replica shared。每个文档属于单独的primary shared。replica shared只是主分片的一个副本。

  • 测试集群健康

curl -XGET 'localhost:9200/_cluster/health?pretty'

三、参考链接

[ElasticSearch 官方网站](https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started.html

相关文章

网友评论

    本文标题:Elasticsearch 入门(二)

    本文链接:https://www.haomeiwen.com/subject/disksxtx.html