标签:
Elasticsearch 依赖 java,在安装 ES 之前首先要配好 java,这个默认我们的电 脑已经完成。
首先从 elasticsearch官网下载安装包,我们是 linux 系统,下载 tar 包比较方便。当前版本为2.3.3,下载地址:Elasticsearch 2.3.3下载
.下载完成之后解压tar文件:
tar -zxvf elasticsearch-2.3.3.tar.gz
启动ElasticSearch命令:
./elasticsearch-2.3.3/bin/elasticsearch
如果一切顺利,会收到类似于如下的信息:
[2016-06-18 15:07:50,106][INFO ][node ] [Maynard Tiboldt] version[2.3.3], pid[7390], build[218bdf1/2016-05-17T15:40:04Z]
[2016-06-18 15:07:50,106][INFO ][node ] [Maynard Tiboldt] initializing ...
[2016-06-18 15:07:50,590][INFO ][plugins ] [Maynard Tiboldt] modules [reindex, lang-expression, lang-groovy], plugins [], sites []
[2016-06-18 15:07:50,609][INFO ][env ] [Maynard Tiboldt] using [1] data paths, mounts [[/ (/dev/disk1)]], net usable_space [85.6gb], net total_space [111.8gb], spins? [unknown], types [hfs]
[2016-06-18 15:07:50,609][INFO ][env ] [Maynard Tiboldt] heap size [990.7mb], compressed ordinary object pointers [true]
[2016-06-18 15:07:50,610][WARN ][env ] [Maynard Tiboldt] max file descriptors [10240] for elasticsearch process likely too low, consider increasing to at least [65536]
[2016-06-18 15:07:52,323][INFO ][node ] [Maynard Tiboldt] initialized
[2016-06-18 15:07:52,323][INFO ][node ] [Maynard Tiboldt] starting ...
[2016-06-18 15:07:52,401][INFO ][transport ] [Maynard Tiboldt] publish_address {127.0.0.1:9300}, bound_addresses {[fe80::1]:9300}, {[::1]:9300}, {127.0.0.1:9300}
[2016-06-18 15:07:52,406][INFO ][discovery ] [Maynard Tiboldt] elasticsearch/OawW12ZERyO3CuQrt7SmFQ
[2016-06-18 15:07:55,445][INFO ][cluster.service ] [Maynard Tiboldt] new_master {Maynard Tiboldt}{OawW12ZERyO3CuQrt7SmFQ}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-join(elected_as_master, [0] joins received)
[2016-06-18 15:07:55,456][INFO ][http ] [Maynard Tiboldt] publish_address {127.0.0.1:9200}, bound_addresses {[fe80::1]:9200}, {[::1]:9200}, {127.0.0.1:9200}
[2016-06-18 15:07:55,457][INFO ][node ] [Maynard Tiboldt] started
[2016-06-18 15:07:55,476][INFO ][gateway ] [Maynard Tiboldt] recovered [0] indices into cluster_state
这样就运行起来了一个节点。(可以多开几个终端,运行起来集群名相同的节点都 在一个集群中).
注意一下有 http 标记的那一行,它提供了有关 HTTP 地址(127.0.0.1)和 端口(9200)的信息,通过这个地址和端口我们就可以访问我们的节点了。默认情况下, Elasticsearch 使用 9200 来提供对其 REST API 的访问。
访问http://127.0.0.1:9200/,浏览器会输出如下信息:
{
"name" : "Obliterator",
"cluster_name" : "elasticsearch",
"version" : {
"number" : "2.3.3",
"build_hash" : "218bdf10790eef486ff2c41a3df5cfa32dadcfde",
"build_timestamp" : "2016-05-17T15:40:04Z",
"build_snapshot" : false,
"lucene_version" : "5.5.0"
},
"tagline" : "You Know, for Search"
}
如果想通过服务器ip访问es,打开elasticsearch-2.3.3/config/elasticsearch.yml,找到Network部分:
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
# network.host: 192.168.0.1
#
# Set a custom port for HTTP:
#
# http.port: 9200
#
# For more information, see the documentation at:
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html>
#
把network.host: 192.168.0.1
前的注释去掉并修改为network.host: 0.0.0.0
重启es上面返回的信息中 http 部分也会变成真实本机地址,可以通过本季真实ip:9200
访问es。
需要对ES节点进行重新启动或正常关机的时候,有三种方法可以关闭ES:
curl -XPOST ‘http://localhost:9200/_shutdown‘
.安装命令:
./elasticsearch-2.3.3/bin/plugin install mobz/elasticsearch-head
安装好后,在浏览器输入地址:http://localhost:9200/_plugin/head/ 即可调用 head 插件 查看集群状态、节点信息、做查询等等。
(a).首先使用git clone
命令下载IK分词器源码
git clone https://github.com/medcl/elasticsearch-analysis-ik.git
也可以直接访问github地址(https://github.com/medcl/elasticsearch-analysis-ik)点击右侧Clone or download按钮,然后Download ZIP直接下载.
(b.)解压下载的elasticsearch-analysis-ik-master.zip.
unzip elasticsearch-analysis-ik-master.zip
(c.)使用maven打包
确保系统已经安装maven,使用mvn -version
命令查看是否已经安装maven.如果没有安装,可以根据系统选择安装方法,比如mac OS系统可以使用brew install maven
命令完成安装.
进入ik分词器的下载目录,运行命令:
mvn package
打包完成以后可以看到根目录下多出一个target
文件夹.
(d.) 配置Ik插件
在elasticsearch-2.3.3/plugins/
目录下新建名为ik的文件夹.把elasticsearch-analysis-ik-master/target/releases
/elasticsearch-analysis-ik-1.9.3.zip解压,把解压后的所有文件拷贝到elasticsearch-2.3.3/plugins/ik/
目录下.
重新启动es,如果配置正确,不会有异常信息输出。
(e.)ik 分词测试
1.首先创建一个索引用于测试:
curl -XPUT localhost:9200/index
2.为索引index创建mapping:
curl -XPOST http://localhost:9200/index/fulltext/_mapping -d‘
{
"fulltext": {
"_all": {
"analyzer": "ik"
},
"properties": {
"content": {
"type" : "string",
"boost" : 8.0,
"term_vector" : "with_positions_offsets",
"analyzer" : "ik",
"include_in_all" : true
}
}
}
}‘
3.测试:
curl ‘http://localhost:9200/index/_analyze?analyzer=ik&pretty=true‘ -d ‘
{
"text":"中国有13亿人口"
}‘
显示结果如下:
{
"tokens" : [ {
"token" : "中国",
"start_offset" : 0,
"end_offset" : 2,
"type" : "CN_WORD",
"position" : 0
}, {
"token" : "国有",
"start_offset" : 1,
"end_offset" : 3,
"type" : "CN_WORD",
"position" : 1
}, {
"token" : "13",
"start_offset" : 3,
"end_offset" : 5,
"type" : "ARABIC",
"position" : 2
}, {
"token" : "亿",
"start_offset" : 5,
"end_offset" : 6,
"type" : "CN_WORD",
"position" : 3
}, {
"token" : "人口",
"start_offset" : 6,
"end_offset" : 8,
"type" : "CN_WORD",
"position" : 4
} ]
}
Relational DB -> Databases -> Tables -> Rows -> Columns
Elasticsearch -> Indices -> Types -> Documents -> Fields
以博客内容管理为例,索引名为blog,类型为article,新加一个文档:
curl -XPUT http://localhost:9200/blog/article/1 -d ‘
{
"id": "1",
"title": "New version of Elasticsearch released!",
"content": "Version 1.0 released today!",
"priority": 10,
"tags": ["announce", "elasticsearch", "release"]
}‘
http://localhost:9200/blog/article/1?pretty
curl -XPOST http://localhost:9200/blog/article/1/_update -d ‘{
"script": "ctx._source.content = \"new content\""
}‘
curl -XDELETE http://localhost:9200/blog/article/1
标签:
原文地址:http://blog.csdn.net/napoay/article/details/51705902