本篇文章首发于我的头条号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. P1880 石子合并

    P1880 石子合并 题目描述 在一个园形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出1个算法,计 ...

  2. Halcon18 Linux For Armv7a 下载

    Halcon18 Linux For Armv7a 下载地址:http://www.211xun.com/download_page_16.html HALCON 18 是一套机器视觉图像处理库,由一 ...

  3. Java开发微信公众号(一)---初识微信公众号以及环境搭建

    ps:1.开发语言使用Java springMvc+Mybaits+spring maven实现 2.使用微信接口测试账号进行本地测试 https://mp.weixin.qq.com/debug/c ...

  4. 为什么对多线程编程这么怕?pthread,sem,mutex,process

    转自http://blog.chinaunix.net/uid-20788636-id-1841334.html 1.线程创建和退出创建线程实际上就是确定调用该线程函数的入口点,这里通常使用的函数是p ...

  5. idea项目多模项目的搭建(复制)

    本文通过一个例子来介绍利用maven来构建一个多模块的jave项目.开发工具:intellij idea. 一.项目结构 multi-module-PRoject是主工程,里面包含两个模块(Modul ...

  6. hdu6136[模拟+优先队列] 2017多校8

    有点麻烦.. /*hdu6136[模拟+优先队列] 2017多校8*/ #include <bits/stdc++.h> using namespace std; typedef long ...

  7. MpLab设置编译文件输出路径

    MpLab设置编译文件输出路径

  8. [51nod 1022] 石子归并v2 [dp+四边形不等式优化]

    题面: 传送门 思路: 加强版的石子归并,现在朴素的区间dp无法解决问题了 首先我们破环成链,复制一条一样的链并粘贴到原来的链后面,变成一个2n长度的序列,在它上面dp,效率O(8n^3) 显然是过不 ...

  9. bzoj1093【ZJOI2007】最大半联通子图

    题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1093 sol  :一开始理解错题意了QAQ,还莫名其妙写挂了QAQ,调了半天 首先显然一个强联 ...

  10. jquery 实践操作:attr()方法

    此篇要记录的是 关于 jquery  的 attr() 方法 在JS中设置节点的属性与属性值用到setAttribute(),获得节点的属性与属性值用到getAttribute(),而在jquery中 ...