Article
elasticsearch startguide
如果有Lucene的使用经历,elasticsearch的入门还是比较简单的。直接解压启动命令就安装好了,然后就是添加一些plugins就OK了。
# 安装
从官网下载 TAR包 ,解压后,运行 elasticsearch 脚本启动服务。
# -d 表示 daemonize 后台运行
[hadoop@cu2 elasticsearch-2.2.0]$ bin/elasticsearch -d
# 插件
大部分插件都是ajax方式的静态页面,可以通过plugin脚本安装,或者直接解压文件到plugins目录下面。
安装已经下载到本地的插件需要加file协议,不然程序会从官网下载。或者直接解压到plugins目录下:
[hadoop@cu2 elasticsearch-2.2.0]$ bin/plugin install file:///home/hadoop/elasticsearch-head-master.zip
-> Installing from file:/home/hadoop/elasticsearch-head-master.zip...
Trying file:/home/hadoop/elasticsearch-head-master.zip ...
Downloading .........DONE
Verifying file:/home/hadoop/elasticsearch-head-master.zip checksums if available ...
NOTE: Unable to verify checksum for downloaded plugin (unable to find .sha1 or .md5 file to verify)
Installed head into /home/hadoop/elasticsearch-2.2.0/plugins/head
windows
E:\local\usr\share\elasticsearch-2.3.3\bin>plugin.bat install file:///D:/SOFTWARE/elasticsearch/elasticsearch-plugin/elasticsearch-head-master.zip
安装好plugin后,打开浏览器查看索引情况: http://localhost:9200/_plugin/head/
# 插件高阶
有些插件版本比较旧需要改一改,需要了解新版本的 elasticsearch-plugin 的规范:
https://www.elastic.co/guide/en/elasticsearch/plugins/2.3/installation.html
新版本插件主要是需要增加一个描述文件:
Plugins require descriptor file
遇到想安装的旧版本的plugin,描述文件写法可以参考 elasticsearch-head 。
可选插件:
- paramedic https://github.com/karmi/elasticsearch-paramedic
- head https://github.com/mobz/elasticsearch-head
- kopf https://github.com/lmenezes/elasticsearch-kopf
# 常用URL请求
# https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html
# 创建
$ curl -XPUT 'http://localhost:9200/t_ods_idc_isp_log2/' -d '{
"settings" : {
"index" : {
"number_of_shards" : 3,
"number_of_replicas" : 0
}
}
}'
{"acknowledged":true}
# https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html
# 更新
# mapping.json
{
"properties": {
"author": {
"type": "string"
},
...
"year": {
"type": "long",
"ignore_malformed": false,
"index": "analyzed"
},
"avaiable": {
"type": "boolean"
}
}
}
$ curl -XPUT 'localhost:9200/t_ods_idc_isp_log2/_mapping/default' -d @mapping.json
$ curl -XPUT 'localhost:9200/t_ods_idc_isp_log2/_mapping/default' -d '
{
"properties": {
"fDIID": {
"type": "string"
},
...
"gatherTime": {
"type": "long"
}
}
}
'
# https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html
# 索引
# documents.json
{ "index": { "_index": "library", "_type": "book", "_id": "1" } }
{ "title": "All Quiet on the Western Front", "otitle": "Im Westen nichts Neues", "author": "Erich Maria Remarque", "year": 1929, "characters": ["Paul Baumer", "Albert Kropp", "Haie Westhus", "Fredrich Muller", "Stanislaus Katczinsky", "Tjaden"], "tags": ["novel"], "copies": 1, "available": true, "section": 3 }
{ "index": { "_index": "library", "_type": "book", "_id": "2" } }
{ "title": "Catch-22", "author": "Joseph Heller", "year": 1961, "characters": ["John Yossarian", "Captain Aardvark", "Chaplain Tappman", "Colonel Cathcart", "Doctor Daneeka"], "tags": ["novel"], "copies": 6, "available": false, "section": 1 }
$ curl -s -XPOST localhost:9200/_bulk --data-binary @documents.json
# 删除
$ curl -XDELETE 'http://localhost:9200/t_ods_idc_isp_log2/'
{"acknowledged":true}
# https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html
# https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html
# 状态查看
http://localhost:9200/_cat/health?v
http://localhost:9200/_cat/nodes?v
http://localhost:9200/_cat/indices?v
curl -XGET 'http://localhost:9200/_all/_mapping/book/field/author'
curl -XHEAD -i 'http://localhost:9200/twitter/tweet'
curl localhost:9200/_stats
curl -XGET 'http://localhost:9200/_all/_mapping/[type]'
–END
Related
Related posts
-
杀鸡焉用牛刀:DuckDB 正取代部分 Spark 场景
2026-02-16
-
基于对象存储的 Spark 数据读写实战:从末尾追加到任意更新
2025-10-28
-
有一种自由叫做程序员的自由:把公众号文章镜像回自己的博客
2026-06-02
-
树莓派 OpenClaw Browser 看不见摸不着?给它配个 VNC 图形环境,踏实安心的Debug
2026-03-09