本篇文章首发于我的头条号Elasticsearch本地环境安装和常用操作,欢迎关注我的头条号和微信公众号“大数据技术和人工智能”(微信搜索bigdata_ai_tech)获取更多干货,也欢迎关注我的CSDN博客


Elasticsearch是一个分布式、RESTful风格的搜索和数据分析引擎。目前已被各大公司广泛的引入生产使用,也已成为大数据生态的重要组成部分。本篇简单介绍一下Elasticsearch的本地安装和一些常用操作。

Elasticsearch使用Java构建,不同版本的Elasticsearch对Java版本要求略有差异,可参考下图来选择Elasticsearch和Java的版本(下图来自官网Support Matrix JVM)。

Elasticsearch本地安装

本地安装Elasticsearch非常简单,首先到官网下载Elasticsearch到本地指定目录,然后解压,进入到Elasticsearch的解压目录下,执行./bin/elasticsearch.\bin\elasticsearch.bat(Windows),可以加上-d参数让Elasticsearch在后台运行。至此,Elasticsearch就安装好了,可以通过curl http://localhost:9200或者用浏览器打开http://localhost:9200/检查是否正常启动,下图这样就表示正常启动了。

常见问题

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

添加下面配置并执行命令:

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.conf

* soft nproc 1024 修改成 * soft nproc 2048

Elasticsearch常用操作

问题三:

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即可)

* 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": {}}}'

修改索引setting

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'

查看所有shards

curl -X GET 'http://localhost:9200/_cat/shards'

查看unassigned shards

curl -X GET 'http://localhost:9200/_cat/shards' | grep UNASSIGNED

Elasticsearch本地环境安装和常用操作的更多相关文章

  1. Flink本地环境安装部署

    本次主要介绍flink1.5.1版本的本地环境安装部署,该版本要求jdk版本1.8以上. 下载flink安装包:http://archive.apache.org/dist/flink/flink-1 ...

  2. Docker安装及常用操作

    Docker简介: Docker是一个轻量级容器技术,类似于虚拟机技术,但性能远远高于虚拟机,Docker支持将软件编译成一个镜像(image),在这个镜像中做好对软件的各种配置,然后可以运行这个镜像 ...

  3. Git的安装及常用操作

    一.Git的安装 1.下载Git,官网地址为:https://git-scm.com/downloads.     2.下载完成之后,双击目录进行安装 3.选择安装目录 4.选择组件,默认即可 5.设 ...

  4. Git安装与常用操作

    Git作为一个版本控制工具,使用前需进行下载安装:可自行到官网下载. 一.安装(windows) 1.双击下载好的文件进行安装,弹窗中点击"next" 2.默认勾选,继续点击&qu ...

  5. Redis可视化工具安装及常用操作操作

    可视化操作工具:RedisDesktopManager 下载地址:http://www.pc6.com/mac/486661.html 直接安装(傻瓜式安装,直接下一步就可以了)(有Mac和windo ...

  6. rsync3.1.3的编译安装和常用操作

    .rsync的编译安装 .tar.gz cd rsync- ./configure --prefix=/usr/local/rsync- --disable-ipv6 .rsync的配置文件: [ro ...

  7. git版本控制工具(二)----本地版本库的常用操作

    ​[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...

  8. 【mongoDB基础篇①】安装与常用操作语句

    简述 mongoDB与redis同为noSql数据库,但是redis为kv数据库(key/value),而mongoDB为文档型数据库存储的是文档(Bson->json的二进制化).内部执行引擎 ...

  9. TortoiseSVN下载,安装,配置,常用操作 svn教程

    一. 首先在百度搜索并下载 TortoiseSVN 推荐从官网下载,软件分为32位和64位版本,下载时请根据自己的系统位数进行下载:

随机推荐

  1. CSS需要注意的问题1(转生活因拼搏而精彩的网易博客)

      1.检查HTML元素(如:<ul>.<div>).属性(如:class=”")是否有拼写错误.是否忘记结束标记(如:<br />) 因为Xhtml 语 ...

  2. POI-java下载excel-HSSFWorkbook

    import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOExceptio ...

  3. Web前端知识体系V0.1

    学习,是一个建立“索引”的过程-好比我们读一本书,读完之后,再次看这本书的目录结构,就会联想起很多书中的具体内容: 博客,是一个回顾所学的载体-学习完教学Video之后,通过书写博客,以达到记忆的目的 ...

  4. Leetcode 558.四叉树交集

    四叉树交集 四叉树是一种树数据,其中每个结点恰好有四个子结点:topLeft.topRight.bottomLeft 和 bottomRight.四叉树通常被用来划分一个二维空间,递归地将其细分为四个 ...

  5. [python][django学习篇][4]django完成数据库代码翻译:迁移数据库(migration)

    上一篇我们已经完成数据库的设计,但是仅仅是python语言,并没有真正创建了数据库表.翻译成数据库语言,真正创建数据库表由django manage.py来实现,这一过程专业术语:迁移数据库 切换到m ...

  6. Spring整合hibernate -hibernateTemplate

    目录 1 在Spring中初始化hibernateTemplate并注入Sessionfactory 2 DAO里注入hibernateTemplate 3 getHibernateTemplate. ...

  7. CodeForces Round #521 (Div.3) B. Disturbed People

    http://codeforces.com/contest/1077/problem/B There is a house with nn flats situated on the main str ...

  8. mysql 修改密码 开启远程访问权限

    修改密码 update user set password=password('') where user='root'; FLUSH   PRIVILEGES; 远程访问权限: GRANT ALL ...

  9. hdu 4258 斜率DP

    思路:dp[i]=dp[j]+(num[i]-num[j+1])^2; #include<iostream> #include<cstring> #include<alg ...

  10. webpack-dev-server版本

    webpack1.x webpack 1.13.2-1.13.3   webpack-dev-server 1.15.0-1.16.0