linux上elasticSearch7.8安装配置
linux上elasticSearch7.8安装配置一、资源准备名称地址说明elasticSearch7.8https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.0-linux-x86_64.tar.gzes安装包jdk11https://www.oracle.com/java/technologies/jav
·
linux上elasticSearch7.8安装配置
一、资源准备
名称 | 地址 | 说明 |
---|---|---|
elasticSearch7.8 | https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.0-linux-x86_64.tar.gz | es安装包 |
jdk11 | https://www.oracle.com/java/technologies/javase-jdk11-downloads.html | jdk安装包 |
上传资源包到/opt/resources目录下。
二、安装配置
- 解压
cd /opt/resources
tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz
mv elasticsearch-7.8.0 /usr/local
- 修改elasticsearch.yml配置文件
vim /usr/local/elasticsearch-7.8.0/config/elasticsearch.yml
-------------------------------------------------------------------------------------------------------------------------
cluster.name: es-hld #为集群提供一个名称
node.name: hld-1 #此节点名称
path.data: /opt/es/data #数据存放的地址
path.logs: /opt/es/logs #日志存放地址
network.host: 0.0.0.0 #网络绑定这样设置就好了
cluster.initial_master_nodes: ["hld-1"] #将es-node1设置为master节点
-------------------------------------------------------------------------------------------------------------------------
- 修改系统进程内存限制
vim /etc/security/limits.conf
-----------------------------------------------------------------------------------------------------------------------
添加数据
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096
-----------------------------------------------------------------------------------------------------------------------
vim /etc/sysctl.conf
-----------------------------------------------------------------------------------------------------------------------
vm.max_map_count=262145 #(es需要262144,我们在基础上+1,保证它启动)
-----------------------------------------------------------------------------------------------------------------------
sysctl -p #刷新
- 创建用户
由于elasticsearch不允许root用户操作,所以需要建立子用户
useradd esuser #增加一个子用户
chown -R esuser:esuser /usr/local/elasticsearch-7.4.2 #赋权
su esuser #切换成子用户
#进入 es/bin命令启动
cd /usr/local/elasticsearch-7.7.0/bin
./elasticsearch -d #-d表示后台启动
- 校验
http:ip:9200 如果返回json字符串则安装成功,如图:
三、es语法
- 获得elasticsearch的状态:(GET)192.168.244.130:9200/
- 新增文档(新增文档会覆盖老的文档的):(PUT)192.168.244.130:9200/nba/_doc/1
字段的mapping是要满足要求的,mapping是不分文档的。
{
“age” : “333”,
“message” : “louis is good”,
“add”: “1”,
“allstar”:“1”,
“rrr”:“rrr”
} - 删除文档:(DELETE)192.168.244.130:9200/nba/_doc/1
- 新增索引:(PUT)192.168.244.130:9200/dba
- 获得索引:(GET)192.168.244.130:9200/dba
- 删除索引:(DELETE)192.168.244.130:9200/dba
- 批量获得索引:(GET)192.168.244.130:9200/dba,cba
- 获取所有索引:(GET)192.168.244.130:9200/_all
- 获取所有索引(详细信息):(GET)192.168.244.130:9200/_cat/indices?v
- 判断索引是否存在:(HEAD)192.168.244.130:9200/dba
- 关闭索引:(POST)192.168.244.130:9200/dba/_close
- 打开索引:(POST)192.168.244.130:9200/dba/_open
- 新增映射(映射是在索引下面得不是下面的):(PUT)192.168.244.130:9200/nba/_mapping
{
“properties”: {
“name”: {
“type”: “text”
},
“team_name”: {
“type”: “text”
},
“position”: {
“type”: “keyword”
},
“play_year”: {
“type”: “keyword”
},
“jerse_no”: {
“type”: “keyword”
}
}
} - 获取映射:(GET)192.168.244.130:9200/nba/_mapping
- 批量获取映射:(GET)192.168.244.130:9200/nba,dba/_mapping
- 获取所有映射:(GET)192.168.244.130:9200/_mapping
- 获取所有映射:(GET)192.168.244.130:9200/_all/_mapping
- 修改映射(不可修改字段的类型,修改字段就是新加字段):(PUT)192.168.244.130:9200/_all/_mapping
{
“properties”: {
“name”: {
“type”: “text”
},
“team_name”: {
“type”: “text”
},
“position”: {
“type”: “keyword”
},
“play_year”: {
“type”: “keyword”
},
“jerse_no”: {
“type”: “keyword”
}
}
} - 新增文档(会自动创建映射,此时要是不存在字段的话按照是不是加双引号看是不是字符串,存在的话long必须是123或者"123"):(PUT)192.168.244.130:9200/nba/_doc/1
{
“namefdy”:“哈登”,
“team_namefdy”:“火箭”,
“positionfdy”:“得分后卫”,
“play_yearfdy”:“10”,
“jerse_nofdy”:“13”
} - 查看文档:(GET)192.168.244.130:9200/nba/_doc/1
- 不指定id新增文档:(PUT)192.168.244.130:9200/nba/_doc
{
“name”:“库里”,
“team_name”:“勇士”,
“position”:“组织后卫”,
“play_year”:“10”,
“jerse_no”:“30”
} - 开启/关闭新增文档自动创建索引:(PUT)192.168.244.130:9200/_cluster/settings
{
“persistent”: {
“action.auto_create_index”: “true/false”
}
} - 查看是否开启自动创建索引:(GET)http://192.168.244.130:9200/_cluster/settings
- 指定操作类型(创建名字一样的文档不覆盖):(PUT)192.168.244.130:9200/nba/_doc/1?op_type=create
- 查看多个文档:(POST)192.168.244.130:9200/_mget
{
“docs” : [
{
“_index” : “nba”,
“_type” : “_doc”,
“_id” : “1”
},
{
“_index” : “nba”,
“_type” : “_doc”,
“_id” : “2”
}
]
} - 查看多个文档:(POST)192.168.244.130:9200/nba/_mget
{
“docs” : [
{
“_type” : “_doc”,
“_id” : “1”
},
{
“_type” : “_doc”,
“_id” : “2”
}
]
} - 查看多个文档:(POST)192.168.244.130:9200/nba/_doc/_mget
{
“docs” : [
{
“_id” : “1”
},
{
“_id” : “2”
}
]
} - 查看多个文档:(POST)192.168.244.130:9200/nba/_doc/_mget
{
“ids” : [“1”, “2”]
} - 修改文档(必须是POST):(POST)192.168.244.130:9200/nba/_update/1
{
“doc”: {
“name”: “哈登”,
“team_name”: “火箭”,
“position”: “双能卫”,
“play_year”: “10”,
“jerse_no”: “13”
}
} - 向_source字段,增加一个字段(必须是POST):(POST)192.168.244.130:9200/nba/_update/1
{
“script”: “ctx._source.age = 18”
} - 从_source字段,删除一个字段(必须是POST):(POST)192.168.244.130:9200/nba/_update/1
{
“script”: “ctx._source.remove(“age”)”
} - 根据参数值,更新指定文档的字段(POST)192.168.244.130:9200/nba/_update/1
{
“script”: {
“source”: “ctx._source.age += params.age”,
“params”: {
“age”: 4
}
}
} - 根据参数值,更新指定文档的字段(POST)192.168.244.130:9200/nba/_update/5
{
“script”: {
“source”: “ctx._source.allstar += params.allstar”,
“params”: {
“allstar”: 4
}
},
“upsert”: {
“allstar”: 1
}
} - 删除文档:(DELETE)192.168.244.130:9200/nba/_doc/1
更多推荐
已为社区贡献1条内容
所有评论(0)