本篇文章首发于个人头条号Elasticsearch本地环境安装和经常使用操做,欢迎关注个人头条号和微信公众号“大数据技术和人工智能”(微信搜索bigdata_ai_tech)获取更多干货,也欢迎关注个人CSDN博客。node
Elasticsearch是一个分布式、RESTful风格的搜索和数据分析引擎。目前已被各大公司普遍的引入生产使用,也已成为大数据生态的重要组成部分。本篇简单介绍一下Elasticsearch的本地安装和一些经常使用操做。shell
Elasticsearch使用Java构建,不一样版本的Elasticsearch对Java版本要求略有差别,可参考下图来选择Elasticsearch和Java的版本(下图来自官网Support Matrix JVM)。json
本地安装Elasticsearch很是简单,首先到官网下载Elasticsearch到本地指定目录,而后解压,进入到Elasticsearch的解压目录下,执行./bin/elasticsearch
或.\bin\elasticsearch.bat
(Windows),能够加上-d
参数让Elasticsearch在后台运行。至此,Elasticsearch就安装好了,能够经过curl http://localhost:9200
或者用浏览器打开http://localhost:9200/
检查是否正常启动,下图这样就表示正常启动了。bootstrap
Elasticsearch的安装很是简单,一般在安装过程当中会遇到一些问题,下面这几个问题是在Ubuntu操做系统安装时常常遇到的问题。浏览器
ERROR: [1] bootstrap checks failed [1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决办法:
切换到root用户修改配置/etc/sysctl.conf
添加下面配置并执行命令:bash
vm.max_map_count=655360 sysctl -p
而后,从新启动elasticsearch,便可启动成功。微信
ERROR: [1] bootstrap checks failed [1]: max number of threads [1024] for user [elasticsearch] is too low, increase to at least [2048]
解决办法:
修改/etc/security/limits.d/90-nproc.confapp
* soft nproc 1024 修改为 * soft nproc 2048
ERROR: [1] bootstrap checks failed [1]: max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
解决办法:
切换到root用户,编辑/etc/security/limits.conf
添加以下内容(其实切换到root用户直接执行ulimit -n 65536
便可)curl
* soft nofile 65536 * hard nofile 131072 * soft nproc 2048 * hard nproc 4096
curl -X PUT 'http://localhost:9200/index_name' -H 'Content-Type: application/json' -d '{ "settings": { ... }, "mappings": { "one": {...}, "two": {...}, ... } }'
curl -X DELETE "http://localhost:9200/index_name"
curl -X DELETE "http://localhost:9200/index_name1,index_name2"
curl -X DELETE "http://localhost:9200/_all" curl -X DELETE "http://localhost:9200/*"
curl -X PUT 'http://localhost:9200/index_name/type_name/id' -H 'Content-Type: application/json' -d '{ "title": "The title", "text": "The text ...", "date": "2019/01/01" }'
curl -X DELETE "http://localhost:9200/index_name/type_name/id"
curl -X POST "http://localhost:9200/_bulk" -H 'Content-Type: application/json' -d ' {"delete":{"_index":"index_name","_type":"main","_id":"1"}} {"delete":{"_index":"index_name","_type":"main","_id":"2"}} '
curl -X POST "http://localhost:9200/index_name/type_name/_delete_by_query?conflicts=proceed" -H 'Content-Type: application/json' -d '{"query": {"match_all": {}}}'
curl -X POST 'http://localhost:9200/index_name' -H 'Content-Type: application/json' -d '{ "settings": { "number_of_shards": 3, "number_of_replicas": 0, "index.mapping.total_fields.limit": 5000 } }'
curl -X POST 'http://localhost:9200/_reindex' -H 'Content-Type: application/json' -d '{ "source": { "index": "index_name_old" }, "dest": { "index": "index_name_new" } }'
curl -X PUT 'http://localhost:9200/_cluster/settings' -H 'Content-Type: application/json' -d'{ "transient": { "cluster.routing.allocation.enable": "none" } }' curl -X PUT 'http://localhost:9200/_cluster/settings' -H 'Content-Type: application/json' -d'{ "transient": { "cluster.routing.allocation.enable": "all" } }' curl -X POST 'http://localhost:9200/_cluster/reroute' -H 'Content-Type: application/json' -d '{ "commands" : [ { "move" : { "index" : "reindex-resharding-test", "shard" : 0, "from_node" : "192.168.0.101", "to_node" : "192.168.0.102" } } ] }'
curl -X GET 'http://localhost:9200/_cluster/health?pretty'
curl -X GET 'http://localhost:9200/_cat/indices?v'
curl -X GET 'http://localhost:9200/_cat/shards'
curl -X GET 'http://localhost:9200/_cat/shards' | grep UNASSIGNED