elasticsearch说明

官网地址:http://www.elasticsearch.org/
1、下载:http://www.elasticsearch.org/downloads/ 解压无须修改即可运行。

2、使用elasticsearch-servicewrapper这个es插件,它支持通过参数,指定是在后台或前台运行es,并且支持启动,停止,重启es服务(默认es脚本只能通过ctrl+c关闭es)。使用方法是到https://github.com/elasticsearch/elasticsearch-servicewrapper下载service文件夹,放到es的bin目录下。下面是命令集合:
bin/service/elasticsearch +
console 在前台运行es
start 在后台运行es
stop 停止es
install 使es作为服务在服务器启动时自动启动
remove 取消启动时自动启动
例子:elasticsearch  start

3、插件安装:(这些插件单机也可以使用)
集群管理插件(集群状态、查询数据、RESTful api的调用等)
安装命令:bin/plugin -install mobz/elasticsearch-head
使用:http://localhost:9200/_plugin/head/
源代码地址:https://github.com/Aconex/elasticsearch-head

集群监控插件(集群状态、cpu、内存等)
安装命令:plugin -install lukas-vlcek/bigdesk
使用:http://localhost:9200/_plugin/bigdesk/
源代码地址:https://github.com/lukas-vlcek/bigdesk

集群监控(感觉是上面两个的综合体,但是功能没有那么齐全,但是界面美观一些)
安装命令:plugin -install royrusso/elasticsearch-HQ
使用:http://localhost:9200/_plugin/HQ/
源代码地址:https://github.com/royrusso/elasticsearch-HQ

搜索建议
安装命令:bin/plugin -install de.spinscale/elasticsearch-plugin-suggest/0.90.5-0.9
源代码地址:https://github.com/spinscale/elasticsearch-suggest-plugin

4、配置中文分词
mmseg 为例:
下载https://github.com/medcl/elasticsearch-analysis-mmseg  这是源代码
可以到https://github.com/medcl/elasticsearch-rtf 下载下来,复制pugin/analysis-mmseg、
config/ mmseg 到自己es对于的目录 中。在config/elasticsearch.yml 文件中添加如下内容:

index:
  analysis:
    tokenizer:
      mmseg_maxword:
          type: mmseg
          seg_type: "max_word"
      mmseg_complex:
          type: mmseg
          seg_type: "complex"
      mmseg_simple:
          type: mmseg
          seg_type: "simple"
到此中文分词配置好了,在新建mapping的时候,设置运用该分词就可以了,如果新建mapping 的时候需要分词但是没有指定分词器就会运用默认的分词器,可以在elasticsearch.yml配置默认分词器:
index.analysis.analyzer.default.type : "mmseg"

5、安装集群
es 不需要任何配置就可以搭建一个集群,它是通过elasticsearch.yml中的 cluster.name (集群名称) 来区分的,新启动一个es会根据cluster.name 加入到对应的集群中去,所以我们在一个局域网中可以配置不同的cluster.name 来建立多个集群。

完成上面所有的配置,复制到多台机子上启动即可。
单机也可做集群,也是复制多个启动即可。(端口会自动递增的)


ElasticSearch 的基本概念

Index
可以把 ElasticSearch 的 Index 理解为 MySQL 的一个数据库。
Type
可以理解为 MySQL 中的一个表
Document
ElasticSearch 中的一个 document 相当于 MySQL 某个表中的一条记录。它是 JSON 结构。
它存储在某个 index(数据库)的某个 type(表)中。
每个 document 都有一个唯一的 id,有不同的字段(field),简直和 MySQL 一模一样。
>> index >> type >> document
Mapping
可以理解为 MySQL 的表结构(table schema)
Cluster
很多个 ElasticSearch 的节点(node)可以构成一个分布式的集群(cluster)。
Shard
每个 index 的数据默认切分到 5 个 shards 中。
有点像 MongoDB,也有点像 MySQL 表的水平分割。

猜你喜欢

转载自horsemen.iteye.com/blog/2244142