docker环境搭建elasticsearch
docker搭建系列
序
本文主要讲如何使用使用docker搭建elasticsearch。
下载镜像
这里利用hangxin1940搭好的镜像,不过是es的1.4.2版本。
docker pull hangxin1940/docker-elasticsearch-cn:v1.6.0
启动容器
docker run -d -p 9200:9200 -p 9300:9300 --name es hangxin1940/docker-elasticsearch-cn:v1.6.0
查看es(这里的ip是docker的default machine的ip
)
访问http://192.168.99.100:9200/
{
status: 200,
name: "node1",
cluster_name: "cn-out-of-box",
version: {
number: "1.6.0",
build_hash: "cdd3ac4dde4f69524ec0a14de3828cb95bbb86d0",
build_timestamp: "2015-06-09T13:36:34Z",
build_snapshot: false,
lucene_version: "4.10.4"
},
tagline: "You Know, for Search"
}
查看集群状态
http://192.168.99.100:9200/_plugin/head/
也可以用命令行
curl -XGET http://192.168.99.100:9200/_cluster/health?pretty
返回
{
"cluster_name" : "cn-out-of-box",
"status" : "yellow",
"timed_out" : false,
"number_of_nodes" : 1,
"number_of_data_nodes" : 1,
"active_primary_shards" : 1,
"active_shards" : 1,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 1,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0
}
这里目前只是单节点的,后续弄成集群看看。
查看插件
http://192.168.99.100:9200/_plugin/oob
增删改查
增加
curl -XPUT 'http://192.168.99.100:9200/twitter/tweet/1' -d '{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elastic Search"
}'
返回
{"_index":"twitter","_type":"tweet","_id":"1","_version":1,"created":true}%
查询
curl -XGET 'http://192.168.99.100:9200/twitter/tweet/1'
返回
{"_index":"twitter","_type":"tweet","_id":"1","_version":1,"found":true,"_source":{
"user" : "kimchy",
"post_date" : "2009-11-15T14:12:12",
"message" : "trying out Elastic Search"
}}%
高级查询:选择字段
curl -XGET 'http://192.168.99.100:9200/twitter/tweet/1?fields=message,user&pretty=true'
返回
{
"_index" : "twitter",
"_type" : "tweet",
"_id" : "1",
"_version" : 1,
"found" : true,
"fields" : {
"message" : [ "trying out Elastic Search" ],
"user" : [ "kimchy" ]
}
}
高级查询:选择格式
curl -XGET 'http://192.168.99.100:9200/twitter/tweet/1?fields=message,user&format=yaml'
返回
---
_index: "twitter"
_type: "tweet"
_id: "1"
_version: 1
found: true
fields:
message:
- "trying out Elastic Search"
user:
- "kimchy"
更新
curl -X PUT http://192.168.99.100:9200/twitter/tweet/1 -d '{"message": "hello world", "user": "codecraft"}'
返回
{"_index":"twitter","_type":"tweet","_id":"1","_version":2,"created":false}%
这个是覆盖更新,不是局部更新:
~ curl -XGET 'http://192.168.99.100:9200/twitter/tweet/1'
{"_index":"twitter","_type":"tweet","_id":"1","_version":2,"found":true,"_source":{"message": "hello world", "user": "codecraft"}}%
删除
curl -XDELETE 'http://192.168.99.100:9200/twitter/tweet/1'
返回
{"found":true,"_index":"twitter","_type":"tweet","_id":"1","_version":3}%
查看mapping
{
"twitter": {
"mappings": {
"tweet": {
"properties": {
"message": {
"type": "string"
},
"post_date": {
"type": "date",
"format": "dateOptionalTime"
},
"user": {
"type": "string"
}
}
}
}
}
}
索引分析
http://192.168.99.100:9200/twitter/_analyze?field=message&text=hello%20world
{
"tokens": [
{
"token": "hello",
"start_offset": 0,
"end_offset": 5,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "world",
"start_offset": 6,
"end_offset": 11,
"type": "<ALPHANUM>",
"position": 2
}
]
}
参考
code-craft
spring boot , docker and so on 欢迎关注微信公众号: geek_luandun
被 6 篇内容引用
推荐阅读
2022年终总结
最近两年开始陷入颓废中,博客也写的越来越少了。究其原因,主要还是陷入了职业倦怠期,最近一次跳槽感觉颇为失败,但是碍于给的薪资高,为了五斗米折腰,又加上最近行情不好,想要往外跳也跳不了,就这样子一直...
codecraft阅读 724
Docker学习:Image的本地存储结构
在使用Docker时候,针对镜像的操作一般就是docker pull,docker build,docker commit(刚开始接触Docker的时候,还不会Dockerfile,经常使用这个命令,但是经历了一次血的教训,已经放弃这个命令很久)这些操作...
backbp赞 4阅读 9.8k评论 3
使用docker快速搭建xssPlatform测试平台实践
笔者之前给一些开发团队多次做Web安全开发培训,为了让培训的学员能够理解XSS原理和XSS的危害,将xssPlatform进行了更新,之前一直放在GitHub中;发现关注的人越来越多,很多人在安装的过程中遇到问题不知道怎么...
汤青松赞 1阅读 25.8k
利用Docker部署管理LDAP及其初次使用
前言:本周主要写了gitlabWebhook转github的项目,总体上没有遇到什么大问题,这周接触到了LDAP,于是就花时间实际操作了解了一下。
李明赞 5阅读 930
Kubernetes v1.26 新特性一览
我每期的 「k8s生态周报」都有一个叫上游进展的部分,所以很多值得关注的内容在之前的文章中已经发过了。这篇中我会再额外介绍一些之前未涵盖的,和之前介绍过的值得关注的内容。
张晋涛赞 2阅读 674评论 1
深入剖析容器网络和 iptables
Docker 能为我们提供很强大和灵活的网络能力,很大程度上要归功于与 iptables 的结合。在使用时,你可能没有太关注到 iptables 的作用,这是因为 Docker 已经帮我们自动完成了相关的配置。
张晋涛赞 3阅读 1.3k
Kubernetes 证书管理系列(一)
大家好,我是张晋涛。这是一个系列文章,将会通过七篇内容和大家一起聊聊 Kubernetes 中的证书管理。以下是内容概览:如上所示,在第一篇中,我们将从原理出发,来理解 Kubernetes 中的证书及其相关的作用,然后...
张晋涛赞 2阅读 855
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。