kibana的安装
镜像下载:
docker pull docker.io/kibana:5.6.8
安装容器:
docker run -it -d -e ELASTICSEARCH_URL=http://192.168.179.132:9200 --name kibana --restart=always -p 5601:5601 kibana:5.6.8
ELASTICSEARCH_URL: 改成自己的ip
访问测试:
http://192.168.179.132:5601
访问成功!
切换到Dev Tools来进行学习 DSL命令
使用谷歌浏览器中文有点冲突
DSL基础语句:
新增索引:
PUT /person
返回结果:
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "person"
}
给索引加个类型:
PUT /person/man/_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
}
}
}
返回结果:
{
"acknowledged": true
}
新增数据:
PUT /person/man/1
{
"name":"李四",
"age":18,
"city":"西安",
"description":"李四爱吃麻辣香锅"
}
PUT /person/man/2
{
"name":"张三",
"age":30,
"city":"重庆",
"description":"张三爱吃火锅"
}
PUT /person/man/3
{
"name":"王五",
"age":55,
"city":"深圳",
"description":"王五爱吃火锅"
}
PUT /person/man/4
{
"name":"赵六",
"age":70,
"city":"广州",
"description":"赵六爱吃肠粉"
}
返回结果:
{
"_index": "person",
"_type": "man",
"_id": "1", (2,3,4)
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"created": true
}
查询所有数据:
GET /person/man/_search #指定类型查询
GET _search #查询所有
GET /person/_search #索引库所有
返回结果:
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "person",
"_type": "man",
"_id": "2",
"_score": 1,
"_source": {
"name": "张三",
"age": 30,
"city": "重庆",
"description": "张三爱吃火锅"
}
},
{
"_index": "person",
"_type": "man",
"_id": "4",
"_score": 1,
"_source": {
"name": "赵六",
"age": 70,
"city": "广州",
"description": "赵六爱吃肠粉"
}
},
{
"_index": "person",
"_type": "man",
"_id": "1",
"_score": 1,
"_source": {
"name": "李四",
"age": 18,
"city": "西安",
"description": "李四爱吃麻辣香锅"
}
},
{
"_index": "person",
"_type": "man",
"_id": "3",
"_score": 1,
"_source": {
"name": "王五",
"age": 55,
"city": "深圳",
"description": "王五爱吃火锅"
}
}
]
}
}
根据id进行查询:
GET /person/man/1
修改数据:(后面得加_update,否则原来数据清空)
POST /person/man/1/_update
{
"doc":{
"name":"李四四",
"city":"漳州"
}
}
使用term查询:
GET /person/man/_search
{
"query": {
"term": {
"city": {
"value": "广州"
}
}
}
}
使用range进行范围查询:
GET /person/man/_search
{
"query": {
"range": {
"age": {
"gte": 10,
"lte": 40
}
}
}
}
排序查询:
GET /person/man/_search
{
"sort": [
{
"age": {
"order": "desc"
}
}
]
}
查询拥有某文档(字段)的数据:
GET /person/man/_search
{
"query": {
"exists":{
"field":"name"
}
}
}
使用match查询:
GET /person/man/_search
{
"query": {
"match": {
"name": "赵六"
}
}
}
match_all查询所有:
GET /person/man/_search
{
"query": {
"match_all": {}
}
}
multi_match指定文档查询:
GET /person/man/_search
{
"query": {
"multi_match": {
"query": "火锅",
"fields": ["description","name"]
}
}
}
需要寻找几个单词时,使用match_phrase查询:
GET /person/man/_search
{
"query": {
"match_phrase": {
"description": "爱吃 火锅"
}
}
}
bool查询:
GET /person/man/_search
{
"query": {
"bool": {
"must": [ #必须满足条件
{
"term": {
"city": {
"value": "广州"
}
}
},
{
"range": {
"age": {
"gte": 10,
"lte": 90
}
}
}
],
"must_not": [ #排除条件
{
"range": {
"age": {
"lte": 50
}
}
}
]
}
}
}
GET /person/man/_search
{
"query": {
"bool": {
"should": [ #满足其中一条即可
{
"term": {
"city": {
"value": "广州"
}
}
},
{
"range": {
"age": {
"gte": 10,
"lte": 40
}
}
}
]
}
}
}
wildcards 通配符查询
GET /person/man/_search
{
"query": {
"wildcard": {
"name": {
"value": "赵*"
}
}
}
}
查询以什么字符开头的prefix 查询:
GET /person/man/_search
{
"query": {
"prefix": {
"name": {
"value": "赵"
}
}
}
}