elasticsearch归纳(kibana使用)

**

倒排索引

**

根据文本找id 

**

数据存储的概念

**

Relationnal DB -> Databases -> Tables -> Rows -> Columns 
elasticsearch  - > indices -> Types ->Doucments  -> Fields

**

kibana操作

**

存入文档
PUT /indices/Types/1 
{
  "name":"aaa",
  "age":22,
  "subject":"cccc",
  "dept":"aaaa"
}

检索:
GET /indices/Types/1	查询id为1的
GET /indices/Types/_search 查询全部
GET /indices/Types/_search?q=name:aa 查询名字有aa的

DSL检索:
GET  /indices/Types/_search
{
  "query": {
    "match": {
      "subject": "human"
    }
  }
}

模糊查询:能容忍查询的某些字母不一样
GET  /indices/Types/_search
{
  "query": {
    "fuzzy": {"subject": "homan"}
  }
}

查询前过滤:  比查询后过滤好 因为先过滤掉会减少查询 而且elasticsearch的过滤有缓存 对日后的查询也会起到帮助
GET /indices/Types/_search
{
  "query": {
    "bool": {
      "filter": {"term": {
          "age": "30"
        }}
      , "must": [
        {"match": {
          "subject": "human"
        }}
      ]
    }
  }
}

查询后过滤:
GET  /indices/Types/_search
{
  "query": {
    "match": {
      "subject": "human"
    }
  }
  , "post_filter": {
    "term": {
      "emp_age": "30"
    }
  }
}

根据范围过滤:
GET  /indices/Types/_search
{
  "query": {
    "bool": {
      "filter": {
        "range": {
          "age": {
            "gt": 20,
            "lt": 50
          }
        }
      }
    }
  }
}

排序:
GET  /indices/Types/_search
{
  "query": {
    "match": {
      "name": "tom jerry"
    }
  }
  , "sort": [
    {
      "age": {
        "order": "asc"
      }
    }
  ]
}

分页查询:
GET   /indices/Types/_search
{
  "query": {
    "match_all": {}
  }
  , "from": 1
  , "size": 1
}

投影查询:只查询出部分的字段
GET   /indices/Types/_search
{
  "query": {
    "match_all": {}
  }
  , "_source": ["age","name"]
}

高亮查询:
GET  /indices/Types/_search
{
  "query": {
    "match": {
      "subject": "human"
    }
  }
  , "highlight": {
    "fields": {"emp_subject": {}}
    , "pre_tags": ["<span style='color:red'>"]
    , "post_tags": ["</span>"]
  }
}

聚合查询:  查询后 基于某个不分词的字段进行分组
GET  /indices/Types/_search
{
  "aggs": {
    "自定义名字": {
      "terms": {
        "field": "emp_dept.keyword",    keyword表示不进行分词
        "size": 10
      }
    }
  }
}
在聚合基础上求平均值并且进行排序:
GET /indices/Types/_search
{
  "aggs": {
    "自定义名字": {
      "terms": {
        "field": "emp_dept.keyword",
        "size": 10,
        "order": {
          "avg_score": "desc"
        }
      },
      "aggs": {
        "avg_score": {
          "avg": {
            "field": "emp_age"
          }
        }
      }
    }
  }
}

获取数据字段的数据类型
GET /indices/_mapping/Types  
PUT	/indices的时候可以指定mapping 在配置了中文分词后可以选择分词库
分词器:中文分词 扩展辞典 远程词典 停止词典

**

elasticsearch内部管理集群的方式

**

一个或者多个节点组成一个集群 具有相同的cluster。name
我们访问的节点负责收集各节点返回的数据 ,最后一起返回给客户端

集群健康度:
green 所有主要分片和复制分片都可用
yellow 所有主要分片可用 但不是所有复制分片可用
red 不是所有主要分片可用

底层是按照分片存储的,当有更多节点的时候 主分片会进行复制分片
下图配置了3个主分片并且每个主分片各有一个复制分片
```![在这里插入图片描述](https://img-blog.csdnimg.cn/20190621151113148.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MDY5NTMyOA==,size_16,color_FFFFFF,t_70)

发布了63 篇原创文章 · 获赞 44 · 访问量 6253

猜你喜欢

转载自blog.csdn.net/weixin_40695328/article/details/93174145