一、安装:
请参考:http://blog.csdn.net/whxaing2011/article/details/18237733
从http://www.elasticsearch.org/下载安装版
从https://github.com/elasticsearch/elasticsearch下载源码
elasticsearch路径不要有中文
解压运行bin/elasticsearch.bat
或者bin/elasticsearch -d -Xms512m -Xmx512m
测试是否成功:
curl -X GET 'http://localhost:9200'
支持的插件路径:https://github.com/elasticsearch
plugin -i elasticsearch/marvel/latest
从 http://download.elasticsearch.org/elasticsearch/marvel/marvel-latest.zip下载
https://github.com/
查看 http://localhost:9200/_plugin/marvel/
plugin -i elasticsearch/kibana
Kibana 是一个功能强大的数据显示客户端
plugin -install mobz/elasticsearch-head
从 https://github.com/medcl/elasticsearch-rtf/archive/master.zip
查看 http://localhost:9200/_plugin/head/
plugin -install lukas-vlcek/bigdesk
bigdesk是集群监控插件,通过该插件可以查看整个集群的资源消耗情况,cpu、内存、http链接等等。
执行命令安装:sudo elasticsearch/bin/plugin -install lukas-vlcek/bigdesk
安装完成之后,在浏览器输入:http://localhost:9200/_plugin/bigdesk/#nodes
plugin -install medcl/elasticsearch-rtf 安装中文分词插件
plugin -i elasticsearch/elasticsearch-hadoop
plugin -install elasticsearch/elasticsearch-mapper-attachments
插件资料:http://www.searchtech.pro/elasticsearch-plugins
二、使用(请参考README文档)
1、角色关系对照
elasticsearch 跟 MySQL 中定义资料格式的角色关系对照表如下
MySQL elasticsearch
database index
table type
table schema mapping
row document
field field
例子1:
1、创建索引,相当于数据库twitter
curl -XPUT 'http://localhost:9200/twitter/user/kimchy' -d '{ "name" : "Shay Banon" }'
返回:
{"_index":"twitter","_type":"user","_id":"kimchy","_version":1,"created":true}
说明:索引库:twitter 表:user 主键id:kimchy 默认版本:1 字段:name 字段值:Shay Banon
2、创建表和提交数据
curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '
{
"user": "kimchy",
"postDate": "2009-11-15T13:12:00",
"message": "Trying out Elasticsearch, so far so good?"
}'
返回:
{"_index":"twitter","_type":"tweet","_id":"1","_version":1,"created":true}
3、提交数据到第2个id
curl -XPUT 'http://localhost:9200/twitter/tweet/2' -d '
{
"user": "kimchy",
"postDate": "2009-11-15T14:12:12",
"message": "Another tweet, will it be indexed?"
}'
返回:
{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"created":true}
4、查看
curl -XGET 'http://localhost:9200/twitter/user/kimchy?pretty=true'
返回:
{
"_index" : "twitter",
"_type" : "user",
"_id" : "kimchy",
"_version" : 1,
"found" : true,
"_source":{ "name" : "Shay Banon" }
}
curl -XGET 'http://localhost:9200/twitter/tweet/1?pretty=true'
返回:
{
"_index" : "twitter",
"_type" : "tweet",
"_id" : "1",
"_version" : 1,
"found" : true,
"_source":
{
"user": "kimchy",
"postDate": "2009-11-15T13:12:00",
"message": "Trying out Elasticsearch, so far so good?"
}
}
curl -XGET 'http://localhost:9200/twitter/tweet/2?pretty=true'
返回:
{
"_index" : "twitter",
"_type" : "tweet",
"_id" : "2",
"_version" : 1,
"found" : true,
"_source":
{
"user": "kimchy",
"postDate": "2009-11-15T14:12:12",
"message": "Another tweet, will it be indexed?"
}
}
范围查询:
curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -d '
{
"query" : {
"range" : {
"postDate" : { "from" : "2009-11-15T13:00:00", "to" : "2009-11-15T14:00:00" }
}
}
}'
5、搜索数据:
搜索所有kimchy提交的tweet
curl -XGET 'http://localhost:9200/twitter/tweet/_search?q=user:kimchy&pretty=true'
json格式查询:
curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty=true' -d '
{
"query" : {
"match" : { "user": "kimchy" }
}
}'
搜索所有的文档:
curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -d '
{
"query" : {
"matchAll" : {}
}
}'
三、配置集群
http://www.csdn123.com/html/mycsdn20140110/b1/b1d8319a211a90ff61d6dee96a0809a4.html
http://my.oschina.net/xiaohui249/blog/228748
1、配置es。这里只做最简单的配置,修改ES_HOME/config/elasticsearch.yml文件,将node.name的值设置为“test-node1”,表示当前这个es服务节点名字为test-node1。
2、启动ES。进入ES安装目录,执行命令:bin/elasticsearch -d -Xms512m -Xmx512m,然后在浏览器输入http://ip:9200/,查看页面信息,是否正常启动。status=200表示正常启动了,还有一些es的版本信息,name为配置文件中node.name的值。
3、在另外一台机器上,安装同样的步骤安装ES,因为至少2台服务才算集群嘛!注意,在配置时,将node.name的值设置为test-node2,总之必须和之前配置值不同。
两台es服务同时起来,因为配置文件中均默认cluster.name=elasticsearch,所以这两台机器自动构建成一个集群,集群名字为elasticsearch。
参考:http://my.oschina.net/xiaohui249/blog/228748
四、常用命令:
关闭 curl -XPOST http://localhost:9200/_cluster/nodes/_shutdown
查看集群状态 curl 'http://localhost:9200/_cluster/health?pretty'
查看集群加载的插件:curl -XGET 'http://localhost:9200/_nodes/plugins'
五、源码集成:
ES有一个好处,那就是可以直接在eclipse里面运行,要想跟踪其代码执行,只需在eclipse里面打断点,然后运行org.elasticsearch.bootstrap包下的Bootstrap.java里面的main方法就行了。
Elasticsearch uses "Maven":http://maven.apache.org for its build system.
In order to create a distribution, simply run the @mvn clean package
-DskipTests@ command in the cloned directory.
The distribution will be created under @target/releases@.
See the "TESTING":TESTING.asciidoc file for more information about
running the Elasticsearch test suite.
http://www.ibm.com/developerworks/cn/java/j-javadev2-24/
请参考:http://blog.csdn.net/whxaing2011/article/details/18237733
从http://www.elasticsearch.org/下载安装版
从https://github.com/elasticsearch/elasticsearch下载源码
elasticsearch路径不要有中文
解压运行bin/elasticsearch.bat
或者bin/elasticsearch -d -Xms512m -Xmx512m
测试是否成功:
curl -X GET 'http://localhost:9200'
支持的插件路径:https://github.com/elasticsearch
plugin -i elasticsearch/marvel/latest
从 http://download.elasticsearch.org/elasticsearch/marvel/marvel-latest.zip下载
https://github.com/
查看 http://localhost:9200/_plugin/marvel/
plugin -i elasticsearch/kibana
Kibana 是一个功能强大的数据显示客户端
plugin -install mobz/elasticsearch-head
从 https://github.com/medcl/elasticsearch-rtf/archive/master.zip
查看 http://localhost:9200/_plugin/head/
plugin -install lukas-vlcek/bigdesk
bigdesk是集群监控插件,通过该插件可以查看整个集群的资源消耗情况,cpu、内存、http链接等等。
执行命令安装:sudo elasticsearch/bin/plugin -install lukas-vlcek/bigdesk
安装完成之后,在浏览器输入:http://localhost:9200/_plugin/bigdesk/#nodes
plugin -install medcl/elasticsearch-rtf 安装中文分词插件
plugin -i elasticsearch/elasticsearch-hadoop
plugin -install elasticsearch/elasticsearch-mapper-attachments
插件资料:http://www.searchtech.pro/elasticsearch-plugins
二、使用(请参考README文档)
1、角色关系对照
elasticsearch 跟 MySQL 中定义资料格式的角色关系对照表如下
MySQL elasticsearch
database index
table type
table schema mapping
row document
field field
例子1:
1、创建索引,相当于数据库twitter
curl -XPUT 'http://localhost:9200/twitter/user/kimchy' -d '{ "name" : "Shay Banon" }'
返回:
{"_index":"twitter","_type":"user","_id":"kimchy","_version":1,"created":true}
说明:索引库:twitter 表:user 主键id:kimchy 默认版本:1 字段:name 字段值:Shay Banon
2、创建表和提交数据
curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '
{
"user": "kimchy",
"postDate": "2009-11-15T13:12:00",
"message": "Trying out Elasticsearch, so far so good?"
}'
返回:
{"_index":"twitter","_type":"tweet","_id":"1","_version":1,"created":true}
3、提交数据到第2个id
curl -XPUT 'http://localhost:9200/twitter/tweet/2' -d '
{
"user": "kimchy",
"postDate": "2009-11-15T14:12:12",
"message": "Another tweet, will it be indexed?"
}'
返回:
{"_index":"twitter","_type":"tweet","_id":"2","_version":1,"created":true}
4、查看
curl -XGET 'http://localhost:9200/twitter/user/kimchy?pretty=true'
返回:
{
"_index" : "twitter",
"_type" : "user",
"_id" : "kimchy",
"_version" : 1,
"found" : true,
"_source":{ "name" : "Shay Banon" }
}
curl -XGET 'http://localhost:9200/twitter/tweet/1?pretty=true'
返回:
{
"_index" : "twitter",
"_type" : "tweet",
"_id" : "1",
"_version" : 1,
"found" : true,
"_source":
{
"user": "kimchy",
"postDate": "2009-11-15T13:12:00",
"message": "Trying out Elasticsearch, so far so good?"
}
}
curl -XGET 'http://localhost:9200/twitter/tweet/2?pretty=true'
返回:
{
"_index" : "twitter",
"_type" : "tweet",
"_id" : "2",
"_version" : 1,
"found" : true,
"_source":
{
"user": "kimchy",
"postDate": "2009-11-15T14:12:12",
"message": "Another tweet, will it be indexed?"
}
}
范围查询:
curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -d '
{
"query" : {
"range" : {
"postDate" : { "from" : "2009-11-15T13:00:00", "to" : "2009-11-15T14:00:00" }
}
}
}'
5、搜索数据:
搜索所有kimchy提交的tweet
curl -XGET 'http://localhost:9200/twitter/tweet/_search?q=user:kimchy&pretty=true'
json格式查询:
curl -XGET 'http://localhost:9200/twitter/tweet/_search?pretty=true' -d '
{
"query" : {
"match" : { "user": "kimchy" }
}
}'
搜索所有的文档:
curl -XGET 'http://localhost:9200/twitter/_search?pretty=true' -d '
{
"query" : {
"matchAll" : {}
}
}'
三、配置集群
http://www.csdn123.com/html/mycsdn20140110/b1/b1d8319a211a90ff61d6dee96a0809a4.html
http://my.oschina.net/xiaohui249/blog/228748
1、配置es。这里只做最简单的配置,修改ES_HOME/config/elasticsearch.yml文件,将node.name的值设置为“test-node1”,表示当前这个es服务节点名字为test-node1。
2、启动ES。进入ES安装目录,执行命令:bin/elasticsearch -d -Xms512m -Xmx512m,然后在浏览器输入http://ip:9200/,查看页面信息,是否正常启动。status=200表示正常启动了,还有一些es的版本信息,name为配置文件中node.name的值。
3、在另外一台机器上,安装同样的步骤安装ES,因为至少2台服务才算集群嘛!注意,在配置时,将node.name的值设置为test-node2,总之必须和之前配置值不同。
两台es服务同时起来,因为配置文件中均默认cluster.name=elasticsearch,所以这两台机器自动构建成一个集群,集群名字为elasticsearch。
参考:http://my.oschina.net/xiaohui249/blog/228748
四、常用命令:
关闭 curl -XPOST http://localhost:9200/_cluster/nodes/_shutdown
查看集群状态 curl 'http://localhost:9200/_cluster/health?pretty'
查看集群加载的插件:curl -XGET 'http://localhost:9200/_nodes/plugins'
五、源码集成:
ES有一个好处,那就是可以直接在eclipse里面运行,要想跟踪其代码执行,只需在eclipse里面打断点,然后运行org.elasticsearch.bootstrap包下的Bootstrap.java里面的main方法就行了。
Elasticsearch uses "Maven":http://maven.apache.org for its build system.
In order to create a distribution, simply run the @mvn clean package
-DskipTests@ command in the cloned directory.
The distribution will be created under @target/releases@.
See the "TESTING":TESTING.asciidoc file for more information about
running the Elasticsearch test suite.
六、支持的api (PHP Java等多种api):
http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/index.html
http://www.oschina.net/p/elasticsearch
中文文档:http://www.elasticsearch.cn/guide/
http://www.ibm.com/developerworks/cn/java/j-javadev2-24/
http://www.searchtech.pro/