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)

發佈了66 篇原創文章 · 獲贊 44 · 訪問量 7332
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章