安装elasticsearch
- docker pull elasticsearch:7.4.2
- docker run -d --name es3 -p 9202:9202 -p 9302:9302 -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -v d:/es/config/es3.yml:/usr/share/elasticsearch/config/elasticsearch.yml c9c606d302fb
安装Kibana
- docker pull elasticsearch:7.2.0
- docker run -d --name kibana -p 5601:5601 -e ELASTICSEARCH_HOSTS=http://192.168.56.1:9200 kibana:7.4.2
操作ES
$hosts = [
'127.0.0.1:9200', //IP+端口
];
$client = \Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();
$params = [
'index' => 'users',
'body' => [
'settings' => [
'number_of_shards' => 3,
'number_of_replicas' => 2
],
'mappings' => [
'_source' => [
'enabled' => true
],
'properties' => [
'name' => [
'type' => 'keyword'
],
'age' => [
'type' => 'integer'
],
'mobile' => [
'type' => 'text'
],
'email' => [
'type' => 'text'
],
'birthday' => [
'type' => 'date'
],
'address' => [
'type' => 'text'
]
]
]
]
];
$response = $client->indices()->create($params);
print_r($response);
$params = [
'index' => 'users',
'id' => 1,
'body' => [
'name' => '张三',
'age' => 10,
'email' => 'zs@gmail.com',
'birthday' => '1990-12-12',
'address' => '北京'
]
];
$client->index($params);
$params = [
'index' => 'users',
'id' => 1
];
$response = $client->get($params);
$params = [
'index' => 'users',
'id' => 1,
'body' => [
'doc' => [
'address' => '测试'
]
]
];
$response = $client->update($params);
print_r($response);
$params = [
'index' => 'users',
'id' => 1,
];
$response = $client->delete($params);
print_r($response);
官方文档