3.Elasticsearch系列--安装
2019-11-17 本文已影响0人
一枼落知天下
Elasticsearch-7.4.2
Install Elasticsearch with RPM
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
/etc/yum.repos.d/elasticsearch.repo
[elasticsearch-7.x]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
sudo yum install elasticsearch
sudo chkconfig --add elasticsearch
sudo systemctl start elasticsearch.service
sudo systemctl stop elasticsearch.service
[root@JhouShuai elasticsearch]# curl -X GET "localhost:9200/?pretty"

修改config目录下的jvm.options
vim jvm.options
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
#-Xms1g
#-Xmx1g
-Xms100m
-Xmx100m
修改config目录下elasticsearch.yml文件
#network.host: 192.168.0.1
#允许任意IP访问
network.host: 0.0.0.0
#http.port: 9200
#修改开放的端口
http.port: 9200
#cluster.initial_master_nodes: ["node-1", "node-2"]
#########这是为解决错误儿添加的 如果没有这个错误请不要添加这个以防出现问题############
##the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] #must be configured
cluster.initial_master_nodes: ["node-1"]
# 最后添加跨域
http.cors.enabled: true
http.cors.allow-origin: "*"
安装问题参考资料Elasticsearch系列--安装


查看健康状态
curl -X GET 127.0.0.1:9200/_cat/health?v
[root@JhouShuai elasticsearch]# curl -X GET 127.0.0.1:9200/_cat/health?v
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1573995159 12:52:39 elasticsearch green 1 1 0 0 0 0 0 0 - 100.0%
[root@JhouShuai elasticsearch]#
查询当前es集群中所有的indices
curl -X GET 127.0.0.1:9200/_cat/indices?v
[root@JhouShuai elasticsearch]# curl -X GET 127.0.0.1:9200/_cat/indices?v
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
创建索引
curl -X PUT 127.0.0.1:9200/www
[root@JhouShuai elasticsearch]# curl -X PUT 127.0.0.1:9200/www
{"acknowledged":true,"shards_acknowledged":true,"index":"www"}
删除索引
[root@JhouShuai elasticsearch]# curl -X DELETE 127.0.0.1:9200/www
{"acknowledged":true}
插入记录
[root@JhouShuai elasticsearch]# curl -H "Content-Type:application/json" -X POST 127.0.0.1:9200/user/person -d '{"name": "dsb","age": 9000,"married": true}'
输出:
{
"_index": "user",
"_type": "person",
"_id": "BPZ5eW4BMLuK5HFc0E3a",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
检索
Elasticsearch的检索语法比较特别,使用GET方法携带JSON格式的查询条件
curl -X GET 127.0.0.1:9200/user/person/_search
{
"took": 501,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "user",
"_type": "person",
"_id": "BPZ5eW4BMLuK5HFc0E3a",
"_score": 1.0,
"_source": {
"name": "dsb",
"age": 9000,
"married": true
}
},
{
"_index": "user",
"_type": "person",
"_id": "4",
"_score": 1.0,
"_source": {
"name": "sb",
"age": 9,
"married": false
}
}
]
}
}