如果需要下载其他版本:
https://github.com/medcl/elasticsearch-analysis-ik/releases
进入容器后运行
cd plugins/
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v5.6.12/elasticsearch-analysis-ik-5.6.12.zip;
unzip elasticsearch-analysis-ik-5.6.12.zip;
mv elasticsearch ik;
rm -rf elasticsearch-analysis-ik-5.6.12.zip;
推出重启容器, 访问下面的 URL
http://192.168.19.129:9200/_analyze?analyzer=ik_smart&pretty=true&text=我是程序员
部署
docker pull kibana:5.6.12;
docker run -it -d -p 5601:5601 -e ELASTICSEARCH_URL=http://192.168.19.129:9200 --name=kibana kibana:5.6.12;
访问
http://192.168.19.129:5601/
# 新增索引库
PUT /user
# 获取所有索引库信息
GET _cat/indices
# 删除索引库
DELETE /user
# 添加映射
PUT /user/userinfo/_mapping
{
"properties": {
"name": {
"type": "text",
"analyzer": "ik_smart",
"search_analyzer": "ik_smart",
"store": false
},
"city": {
"type": "text",
"analyzer": "ik_smart",
"search_analyzer": "ik_smart",
"store": false
},
"age": {
"type": "long",
"store": false
},
"description": {
"type": "text",
"analyzer": "ik_smart",
"search_analyzer": "ik_smart",
"store": false
}
}
}
# 添加文本数据 id=1
PUT /user/userinfo/1
{
"name": "张三",
"city": "上海",
"age": 20,
"description": "张三是一名是中国上海人"
}
# 添加文本数据 id=2
PUT /user/userinfo/2
{
"name": "李四",
"city": "北京",
"age": 25,
"description": "李四到北京实习"
}
# 根据 ID 查询数据 id=2
GET /user/userinfo/2
# 更新文本数据 id=2 (原理: 删除原始数据, 新增数据)
PUT /user/userinfo/2
{
"age": 30,
"description": "李四在北京工作"
}
# 更新数据, 直接修改指定域的数据.
POST /user/userinfo/2/_update
{
"doc": {
"age": 45,
"description": "李四在北京工作, 当上 CEO."
}
}
# 查询索所有数据
GET _search
# 查询索引库所有数据
GET /user/_search
# 查询索引库下文档所有数据
GET /user/userinfo/_search
# 根据 age 降序排列
GET /user/userinfo/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"age": {
"order": "desc"
}
}
]
}
# 分页查询
GET /user/userinfo/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"age": {
"order": "desc"
}
}
],
"from": 0,
"size": 1
}
# 词项搜索 Term
GET /user/userinfo/_search
{
"query": {
"term": {
"city": {
"value": "上海"
}
}
}
}
# 多个词项搜索 Terms
GET /user/userinfo/_search
{
"query": {
"terms": {
"city": [
"上海",
"北京"
]
}
}
}
# 范围过滤搜索
GET /user/userinfo/_search
{
"query": {
"range": {
"age": {
"gte": 10,
"lte": 26
}
}
},
"sort": [
{
"age": {
"order": "desc"
}
}
]
}
# 范围存在域的数据
GET /user/userinfo/_search
{
"query": {
"exists": {
"field": "age"
}
}
}
# bool 过滤数据
# must ==> and, must_not ==> not, should ==> or.
GET /user/userinfo/_search
{
"query": {
"bool": {
"must": [
{
"terms": {
"city": [
"上海",
"北京"
]
}
},
{
"range": {
"age": {
"gte": 10,
"lte": 20
}
}
}
]
}
}
}
# 查询所有
GET /user/userinfo/_search
{
"query": {
"match_all": {}
}
}
# 字符串查询
GET /user/userinfo/_search
{
"query": {
"match": {
"description": "北京"
}
}
}
# 多个域字符串查询
GET /user/userinfo/_search
{
"query": {
"multi_match": {
"query": "北京",
"fields": [
"city",
"description"
]
}
}
}
需要进入容器将
kibana.yml
文件中的http://elasticsearch:9200
改成自己的 Elasticsearch 的地址连接
vi config/kibana.yml
关于使用, 只有一点区别, 就是 7 版本以上
去除了
type
, 提高了搜索. 8 版本可以设置是否启动 type. 其他的基本上一样