文章目录[隐藏]
Elaticsearch,简称为es, es是一个开源的高扩展的分布式全文检索引擎,它可以近乎实时的存储、检索数据;本身扩展性很好,可以扩展到上百台服务器,处理PB级别的数据。es也使用Java开发并使用Lucene作为其核心来实现所有索引和搜索的功能,但是它的目的是通过简单的RESTful API来隐藏Lucene的复杂性,从而让全文搜索变得简单。
创建网络
docker network create es
配置ElasticSearch
- 创建目录
这个路径和ES路径没啥关系,有尝试直接对应,但启动总是报文件错误就放弃了。
mkdir /app/elasticsearch
- 在该目录下创建配置文件
cluster.name: "docker-cluster"
network.host: 0.0.0.0
#----------------------- BEGIN SECURITY AUTO CONFIGURATION -----------------------
#
# The following settings, TLS certificates, and keys have been automatically
# generated to configure Elasticsearch security features on 20-06-2022 07:34:02
#
# --------------------------------------------------------------------------------
# Enable security features
xpack.security.enabled: false
xpack.security.enrollment.enabled: true
# Enable encryption for HTTP API client connections, such as Kibana, Logstash, and Agents
xpack.security.http.ssl:
enabled: false
keystore.path: certs/http.p12
# Enable encryption and mutual authentication between cluster nodes
xpack.security.transport.ssl:
enabled: true
verification_mode: certificate
keystore.path: certs/transport.p12
truststore.path: certs/transport.p12
# Create a new cluster with the current node only
# Additional nodes can still join the cluster later
cluster.initial_master_nodes: ["246f39b02d6b"]
http.cors.enabled: true
http.cors.allow-origin: "*"
#----------------------- END SECURITY AUTO CONFIGURATION -------------------------
- 创建ES
docker run --name search -it -d -v /app/elasticsearch:/usr/share/elasticsearch/conf -p 9200:9200 -p 9300:9300 --net es elasticsearch:8.2.3
- 进入ES并修改配置文件
ES里面的vi会乱码,这个很奇葩
docker exec -it search sh
cp conf/* config
docker restart search
配置elasticsearch-head
你可理解这就是一个Web客户端,只是感觉有点过于老了,5年前的东西了。
docker run -p 9100:9100 --net es mobz/elasticsearch-head:5
Test
创建一个名为hello的索引,注意不同的ES版本格式有不同的要求。
curl -X PUT -H "Content-Type: application/json" -d '{
"settings": {
"number_of_shards": 3,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"name": {
"type": "text"
},
"country": {
"type": "keyword"
},
"age": {
"type": "integer"
},
"date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
}
}
}
}' http://localhost:9200/hello