ElasticSearch入门

[url]http://www.muxuanli.com/lmx/[/url]

1. 下载zip 文件,解压 到E:\tools\elasticsearch\bin 目录下 打开 elasticsearch.bat
http://localhost:9200

2. 安装 elasticsearch-head 插件
bin目录运行以下命令: plugin install mobz/elasticsearch-head

3. 安装 bigdesk 插件 plugin install lukas-vlcek/bigdesk

https://www.elastic.co/guide/en/elasticsearch/plugins/2.3/installation.html

插件的作用:

elasticsearch-head:

bigdek:bigdesk是elasticsearch的一个集群监控工具,可以通过它来查看es集群的各种状态,如:cpu、内存使用情况,索引数据、搜索情况,http连接数等。

[img]http://dl.iteye.com/upload/picture/pic/137537/13ed0449-8d9f-3a1c-887b-1522d9d55d2e.png[/img]

Elasticsearch把数据存储在一个或多个[color=red]索引[/color]上,每个索引包含各种类型的[color=red]文档[/color]!

Elasticsearch 使用文档的唯一标识符来计算文档应该被放到哪个分片中。索引请求发送到一个节点后,该节点会转发文档到持有相关分片的目标节点中。



[i][b]增删改查操作[/b][/i]



一. 创建:

curl -XPUT "http://localhost:9200/blog/article/1" -d '
{
"title":"About MaiMeng Tech",
"content":"MaiMeng Tach Suzhou China & Very Good",
"tags":["WEB","2020","TECH"]
}
'

返回:
{
"_index": "blog",
"_type": "article",
"_id": "1",
"_version": 1,
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": true
}


二. 获取:

curl -XGET http://localhost:9200/blog/article/1

返回:
{"_index":"blog","_type":"article","_id":"1","_version":1,"found":true,"_source"
:{
"title":"About MaiMeng Tech",
"content":"MaiMeng Tach Suzhou China & Very Good",
"tags":["WEB","2020","TECH"]
}}


三. 更新:_update 注意:不需要发送整个文档,只需要发送改变的部分。更新时需要使用_source字段;如果更新时新增一个字段,使用upsert

curl -XPOST http://localhost:9200/blog/article/1/_update -d '{
"script":"ctx._source.content = \"This is new content\""
}'

报错:
{
"error": {
"root_cause": [
{
"type": "remote_transport_exception",
"reason": "[Gamora][127.0.0.1:9300][indices:data/write/update[s]]"
}
],
"type": "illegal_argument_exception",
"reason": "failed to execute script",
"caused_by": {
"type": "script_exception",
"reason": "scripts of type [inline], operation [update] and lang [groovy] are disabled"
}
},
"status": 400
}

http://www.open-open.com/lib/view/open1455238146511.html
在最新版本的Elasticsearch中,基于安全考虑(如果用不到,请保持禁用),默认禁用了动态脚本功能.如果被禁用,则报上述错误。
可以用以下方式完全开启动态脚本功能,在config/elasticsearch.yml文件,在最后添加以下代码:
script.inline: on
script.indexed: on
script.file: on

配置后,重启Elasticsearch。

执行结果: {"_index":"blog","_type":"article","_id":"1","_version":4,"_shards":{"total":2,"successful":1,"failed":0}}


四. 删除

curl -XDELETE http://localhost:9200/blog/article/1



[i][b]
MySQL数据同步到ES[/b][/i]




curl -XDELETE localhost:9200/estest
// curl -XDELETE localhost:9200/_river/estest


创建索引 estest
curl -XPUT http://localhost:9200/estest/

创建表与索引映射
curl -XPUT 'http://localhost:9200/estest/employee/_mapping' -d '
{
"employee":{
"_all": { "enabled": false},
"_source" : {"enabled" : true},
"properties" : {
"id" : {"type" : "long","index" : "not_analyzed"},
"name" : {"type" : "string","index" : "no"},
"job" : {"type" : "string","index" : "no"}
}
}
}'

运行river同步数据
curl -XPUT 'http://localhost:9200/_river/estest/_meta' -d '
{
"type": "jdbc",
"jdbc": {
"driver": "com.mysql.jdbc.Driver",
"url": "jdbc:mysql://localhost:3306/es",
"user": "root",
"password": "123456",
"sql": "select id, id as \"_id\",name,job from t_employee",
"index": "estest",
"type": "employee"
}
}'


"jdbc": {
"driver": "com.mysql.jdbc.Driver",
"url": "jdbc:mysql://localhost:3306/es",
"user": "root",
"password": "123456",
"sql": "select id, id as as \"_id\",name,job from employee",
"index": "estest",
"type": "employee",
"bulk_size": 100,
"max_bulk_requests": 30,
"bulk_timeout": "10s",
"flush_interval": "5s",
"schedule": "0 0-59 0-23 ? * *"
}




curl localhost:9200/estest/_count?pretty=true

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值