docker安装kibana以及Dev Tools的DSL基础语句入门

1 篇文章 0 订阅
1 篇文章 0 订阅

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
kibana初始界面
访问成功!

切换到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": "赵"
      }
    }
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值