kibana
官网下载
修改配置文件
修改vi config/kibana.yml
elasticsearch.url: “http://localhost:9200”
改成对应的地址
后台启动
nohup ./bin/kibana &
查询操作
1.索引库操作
PUT /库名
{
"settings": {
"number_of_shards": 1, //分片
"number_of_replicas": 1//备份
}
}
GET /库名
DELETE /库名
2.创建映射字段
PUT /库名/_mapping/表名
{
"properties": {
"字段名": {
"type": "text",
"index": true,
"store": true,
"analyzer": "ik_max_word"
}
}
}
-
type:
string类型,分两种:
text:可分词,不可参与聚合
keyword:不可分词,数据会作为完整的字段进行匹配,可以参与聚合
Numerical:数值类型
基本数据类型:long、integer、strot、byte、double、float、half_float
浮点数的高精度类型:scaled_float
需要指定一个精度因子,比如10或100。elasticsearch会吧真实值乘以这个因子后存储,取出时再还原。
Date:日期类型 -
index:
是否索引 -
store:
是否将数据额外存储
默认为false 一般都不需要设置
在elasticearch ,即便store为false,也可以搜索到结果。
我们在显示的时候可以使用_source属性中设置 过滤结果。
新增修改
PUT /test/prodect/1
{
"name":"冰箱海尔"
}
如果添加未定义的字段 es会自动创建字段 并判断类型
如果存储的是string类型数据,es无法智能判断,他就会存两个字段。
例如:
- name:text类型
- name.keyword:keyword类型
删除
DELETE /test/prodect/1
查询
GET /test/prodect/1
GET /test/_search
{
"query": {"match_all": {}}
}
match_all查所有
match全文检索查询
模糊匹配or 只要分词匹配就展示
GET /test/_search
{
"query": {"match": {
"name": "冰箱2"
}}
}
完全匹配and 所有匹配才展示
GET /test/_search{
"query": {"match": {
"name": {"": "冰箱2","operator": "and"}
}}
}
匹配度
GET /test/_search{
"query": {"match": {
"name": {"query": "冰箱2","minimum_should_match": "75%"}
}}
}
多字段查询(multi_match)
GET /test/_search{
"query": {
"multi_match": {
"query": "冰箱2",
"fields": ["title","name"]
}
}
}
range范围
term词条匹配 不分词查询 精确匹配
GET /test/_search{
"query": {
"term": {
"name": "冰箱2"
}
}
}
_source 结果过滤
GET /test/_search
{
"_source": "name",
"query": {"match": { "name": {"query": "冰箱2","operator": "and"}
}}
}
filter 过滤条件
聚合统计
GET /company/_search
{
"size": 1,
"aggs": {
"popularName": {
"terms": {
"field":"age"
}
}
}
}
GET /company/_search
{
"size": 1,
"aggs": {
"popularName": {
"terms": {
"field":"age"
},"aggs": {
"sumName": {
"sum": {
"field":"price"
}
}
}
}
}
}
分词器