本篇文章首发于我的头条号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. Spring MVC学习总结

    Spring MVC学习总结 Spring MVC学习路(一) 下载配置文件 Spring MVC学习路(二) 设置配置文件 Spring MVC学习路(三) 编写第一个demo Spring MVC ...

  2. hibernate 出错 集合

    Lazy="false"反而出错 错误信息: “System.Configuration.ConfigurationErrorsException”类型的异常在 Spring.Co ...

  3. 第九届极客大挑战 部分WP

    CODE 和0xpoker分0day 百度 取石子游戏. https://blog.csdn.net/qq_33765907/article/details/51174524 已经说得很详细了,慢慢来 ...

  4. python 学习分享-迭代器与生成器篇

    迭代器 迭代是Python最强大的功能之一,是访问集合元素的一种方式.. 迭代器是一个可以记住遍历的位置的对象. 迭代器对象从集合的第一个元素开始访问,直到所有的元素被访问完结束.迭代器只能往前不会后 ...

  5. Docker Hadoop LAMP安装配置教程

    以下教程来自九章算法. 1.How to install Dockerhttps://bupt.quip.com/YehSAR4qnGqB 2.How to set up hadoop environ ...

  6. Log4j官方文档翻译(三、配置)

    之前的章节介绍了log4j的核心组件,本章将会通过配置文件介绍一下核心组建的配置. 主要在配置文件中配置log4j的日志级别,定义appender.layout等. log4j.properties是 ...

  7. cf 843 D Dynamic Shortest Path [最短路+bfs]

    题面: 传送门 思路: 真·动态最短路 但是因为每次只加1 所以可以每一次修改操作的时候使用距离分层的bfs,在O(n)的时间内解决修改 这里要用到一个小技巧: 把每条边(u,v)的边权表示为dis[ ...

  8. Redis主从复制简单介绍

    由于本地环境的使用,所以搭建一个本地的Redis集群,本篇讲解Redis主从复制集群的搭建,使用的平台是Windows,搭建的思路和Linux上基本一致! (精读阅读本篇可能花费您15分钟,略读需5分 ...

  9. POJ3678 Katu Puzzle 【2-sat】

    题目 Katu Puzzle is presented as a directed graph G(V, E) with each edge e(a, b) labeled by a boolean ...

  10. Brain Powerd计划

    Brain Powerd这片子没有高清的版本,只有DVD..(我手上只有个DVDRip,X2字幕组的)同时字幕质量也不行. 开个坑用waifu2x压个好看一点(用DVDRip)的,码率大概是3.3M ...