elasticsearch 核心概念

转自大数据学习平台-大讲台:
http://www.dajiangtai.com/course/search.do?search=elastic

一、分片(shards)
  1. 一个索引库默认有5个分片,如果想更改分片数,必须在创建索引库的时候指定
POST /{indexname}  -d {"settings":{"shards":5}}
例:
curl -XPOST http://hadoop01:9200/djtshards -d '{"settings":{"shards":5}}'
  1. 默认一个分片可以存储2,147,483,519条数据。
  2. 分片可以使得节点的压力均衡
二、副本(replactions)
  1. 默认一个分片有一个副本,可以在创建索引库的时候指定副本数量
-d {"settings":{"number_of_replacations":2}}

也可以在索引库已经存在的情况下更新副本数量

PUT /{indexname}/_settings   -d {"index":"number_of_replacations":1}}
  1. 分片可以提高系统的容错性,主分片和副本一定式分布在不同的节点上的。
三、Recover
  1. es在有节点加入或者退出时,会重新分配分片及副本的分布。
  2. es集群节点地位平等,不存在单点故障,有两种发现机制:Zen和Ec2
  3. Zen配置:
#集群节点发现机制配置
#不使用默认的组播方式,改用单播方式(Point to Point)
discovery.zen.ping.multicast.enables: false
discovery.zen.ping_timeout: 120s
client.transport.ping_timeout: 60s

#单播的目标节点的ip或者hostname
discovery.zen.ping.unicast.hosts: ["192.168.174.20", "192.168.174.21", "192.168.174.22"]
四、gateway(数据持久化)
  1. hdfs方式
    首先要安装插件,在github上查看下es于es-hdfs插件对应的版本
    —————————————————————–
| Hadoop Plugin    | ElasticSearch    | Embedded Hadoop Version |
-----------------------------------------------------------------
| master           | 0.21 -> master   | 0.20.204.0              |
-----------------------------------------------------------------
| 1.2.0            | 0.19 -> 0.20     | 0.20.204.0              |
-----------------------------------------------------------------
| 1.1.0            | 0.19 -> 0.20     | 0.20.204.0              |
-----------------------------------------------------------------
| 1.0.0            | 0.18             | 0.20.204.0              |
-----------------------------------------------------------------

bin/plugin install elasticsearch/elasticsearch-repository-hdfs/2.2.0

修改配置文件 config/elasticsearch.yml
     gateway:
          type: hdfs
     gateway:
          hdfs:
          uri: hdfs://cluster1/
五、mapping(索引)
  1. 即为索引类型的定义,类型的名称,类型有哪些属性(字段)
  2. 查看某个索引库的索引信息:
GET /{indexname}/_mapping?pretty

{
  "djt" : {
    "mappings" : {
      "user" : {
        "properties" : {
          "age" : {
            "type" : "long"
          },
          "name" : {
            "type" : "string"
          }
        }
      }
    }
  }
}
  1. 创建mapping
PUT /{indexname}/ -d {"mappings":{"user":{"properties":{"name":{"type":"string"}}}}}
  1. 更新mapping
         POST /{indexname}/{typename} -d {"properties":{"name":{"type":"string"}}}

猜你喜欢

转载自blog.csdn.net/wenxindiaolong061/article/details/79952215