linux上elasticSearch7.8安装配置

es基本语法

一、资源准备

名称地址说明
elasticSearch7.8https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.8.0-linux-x86_64.tar.gzes安装包
jdk11https://www.oracle.com/java/technologies/javase-jdk11-downloads.htmljdk安装包

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语法

  1. 获得elasticsearch的状态:(GET)192.168.244.130:9200/
  2. 新增文档(新增文档会覆盖老的文档的):(PUT)192.168.244.130:9200/nba/_doc/1
    字段的mapping是要满足要求的,mapping是不分文档的。
    {
    “age” : “333”,
    “message” : “louis is good”,
    “add”: “1”,
    “allstar”:“1”,
    “rrr”:“rrr”
    }
  3. 删除文档:(DELETE)192.168.244.130:9200/nba/_doc/1
  4. 新增索引:(PUT)192.168.244.130:9200/dba
  5. 获得索引:(GET)192.168.244.130:9200/dba
  6. 删除索引:(DELETE)192.168.244.130:9200/dba
  7. 批量获得索引:(GET)192.168.244.130:9200/dba,cba
  8. 获取所有索引:(GET)192.168.244.130:9200/_all
  9. 获取所有索引(详细信息):(GET)192.168.244.130:9200/_cat/indices?v
  10. 判断索引是否存在:(HEAD)192.168.244.130:9200/dba
  11. 关闭索引:(POST)192.168.244.130:9200/dba/_close
  12. 打开索引:(POST)192.168.244.130:9200/dba/_open
  13. 新增映射(映射是在索引下面得不是下面的):(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”
    }
    }
    }
  14. 获取映射:(GET)192.168.244.130:9200/nba/_mapping
  15. 批量获取映射:(GET)192.168.244.130:9200/nba,dba/_mapping
  16. 获取所有映射:(GET)192.168.244.130:9200/_mapping
  17. 获取所有映射:(GET)192.168.244.130:9200/_all/_mapping
  18. 修改映射(不可修改字段的类型,修改字段就是新加字段):(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”
    }
    }
    }
  19. 新增文档(会自动创建映射,此时要是不存在字段的话按照是不是加双引号看是不是字符串,存在的话long必须是123或者"123"):(PUT)192.168.244.130:9200/nba/_doc/1
    {
    “namefdy”:“哈登”,
    “team_namefdy”:“火箭”,
    “positionfdy”:“得分后卫”,
    “play_yearfdy”:“10”,
    “jerse_nofdy”:“13”
    }
  20. 查看文档:(GET)192.168.244.130:9200/nba/_doc/1
  21. 不指定id新增文档:(PUT)192.168.244.130:9200/nba/_doc
    {
    “name”:“库里”,
    “team_name”:“勇士”,
    “position”:“组织后卫”,
    “play_year”:“10”,
    “jerse_no”:“30”
    }
  22. 开启/关闭新增文档自动创建索引:(PUT)192.168.244.130:9200/_cluster/settings
    {
    “persistent”: {
    “action.auto_create_index”: “true/false”
    }
    }
  23. 查看是否开启自动创建索引:(GET)http://192.168.244.130:9200/_cluster/settings
  24. 指定操作类型(创建名字一样的文档不覆盖):(PUT)192.168.244.130:9200/nba/_doc/1?op_type=create
  25. 查看多个文档:(POST)192.168.244.130:9200/_mget
    {
    “docs” : [
    {
    “_index” : “nba”,
    “_type” : “_doc”,
    “_id” : “1”
    },
    {
    “_index” : “nba”,
    “_type” : “_doc”,
    “_id” : “2”
    }
    ]
    }
  26. 查看多个文档:(POST)192.168.244.130:9200/nba/_mget
    {
    “docs” : [
    {
    “_type” : “_doc”,
    “_id” : “1”
    },
    {
    “_type” : “_doc”,
    “_id” : “2”
    }
    ]
    }
  27. 查看多个文档:(POST)192.168.244.130:9200/nba/_doc/_mget
    {
    “docs” : [
    {
    “_id” : “1”
    },
    {
    “_id” : “2”
    }
    ]
    }
  28. 查看多个文档:(POST)192.168.244.130:9200/nba/_doc/_mget
    {
    “ids” : [“1”, “2”]
    }
  29. 修改文档(必须是POST):(POST)192.168.244.130:9200/nba/_update/1
    {
    “doc”: {
    “name”: “哈登”,
    “team_name”: “火箭”,
    “position”: “双能卫”,
    “play_year”: “10”,
    “jerse_no”: “13”
    }
    }
  30. 向_source字段,增加一个字段(必须是POST):(POST)192.168.244.130:9200/nba/_update/1
    {
    “script”: “ctx._source.age = 18”
    }
  31. 从_source字段,删除一个字段(必须是POST):(POST)192.168.244.130:9200/nba/_update/1
    {
    “script”: “ctx._source.remove(“age”)”
    }
  32. 根据参数值,更新指定文档的字段(POST)192.168.244.130:9200/nba/_update/1
    {
    “script”: {
    “source”: “ctx._source.age += params.age”,
    “params”: {
    “age”: 4
    }
    }
    }
  33. 根据参数值,更新指定文档的字段(POST)192.168.244.130:9200/nba/_update/5
    {
    “script”: {
    “source”: “ctx._source.allstar += params.allstar”,
    “params”: {
    “allstar”: 4
    }
    },
    “upsert”: {
    “allstar”: 1
    }
    }
  34. 删除文档:(DELETE)192.168.244.130:9200/nba/_doc/1
Logo

更多推荐