07_Kibana界面操作ES


Kibana界面的API操作ES

1.創建索引

1.1 指定分片數量和備份數量

image

1.2 創建默認

image

 

2. 查看索引

image

2.1 查看單個索引設置

image

2.2 查看所有索引設置

image

3.文檔管理

3.1 添加文檔

3.1.1 PUT

image

3.1.2 POST方式

可以不指定ID,會自動生成一個ID

image

3.2 查看文檔

3.2.1 查看文檔全部內容

image

3.2.2 查看文檔部分內容

image

 

3.3 修改文檔

3.3.1 PUT方式

覆蓋

image

3.3.2 POST方式

只修改部分數據,而不是覆蓋

image

3.4 刪除文檔

image

4. 刪除索引

image

 

5.批量操作

5.1. _mget

5.1.1 同時獲取多個文檔

image

5.1.2 同時獲取多個文檔的部分內容

image

索引相同的話,可以簡寫為如下形式

image

image

5.2. _bulk

{action:{metadata}}
{requestbody}

action:(行為)

  • create:文檔不存在時創建

  • update: 更新文檔

  • index:創建新文檔或替換已有文檔

  • delete:刪除一個文檔

metadata:_index,_type,_id

5.2.1 創建

image

6. Query查詢

6.1 簡單查詢

image

GET /lib3/user/_search?q=name:lisi

image

# 篩選出包含唱歌的,並且按照年齡從大到小排序
GET /lib3/user/_search?q=internets:changge&sort=age:desc
6.2 term查詢和terms查詢

會根據倒排索引尋找確切的term,並不知道分詞器的存在,適合keywordnumericdate

image

6.3 match查詢

知道分詞器的存在,會對field進行分詞操作,然后再查詢

image

6.3.1 multi_match

可以從多個字段中篩選出query包含的詞

image

6.3.2 match_phrase

短語匹配

image

6.4 wildcard查詢

支持使用通配符*?來進行查詢 *代表0或多個字符 ? 表示任意一個字符

image

GET /lib3/user/_search
{
  "query": {
    "wildcard": {
      "name": "zhao*"
    }
  }
}

image

GET /lib3/user/_search
{
  "query": {
    "wildcard": {
      "name": "zhaol?u"
    }
  }
}
6.5 fuzzy查詢

實現模糊查詢,只能少一個字符,多個字符依然無法查詢到

image

高亮

篩選字段和高亮字段要一致

image

6.6 基於中文的查詢

安裝ik插件

ik_max_word : 會將文本做最細粒度的拆分;盡可能多的拆分出詞語 ik_smart: 做最粗粒度拆分;已經被分出的詞語不會再被其他詞語占有

# 環境構建
PUT /lib4
{
  "settings": {
    "number_of_replicas": 1,
    "number_of_shards": 5
  },
  "mappings": {
    "user" :{
      "properties": {
        "name" : {"type": "text","analyzer": "ik_max_word"},
        "address" : {"type": "text","analyzer": "ik_max_word"},
        "age" : {"type": "integer"},
        "internets" : {"type": "text", "analyzer": "ik_max_word"},
        "birthday" : {"type" : "date"}
      }
    }  
  }
}

image

from:指定初始位置,size表示長度

6.7 指定返回字段
GET /lib4/user/_search
{
  "_source": ["address","name"],
  "query": {
    "match": {
      "internets": "唱歌"
    }
  }
}

image

# include 包含
GET  /lib4/user/_search
{
  "query": {
    "match": {
      "internets": "唱歌"
    }
  }, 
  "_source": {
    "includes": ["name","address"]
  }
}
# 不包含
GET  /lib4/user/_search
{
  "query": {
    "match": {
      "internets": "唱歌"
    }
  }, 
  "_source": {
     "excludes": ["age","birthday"]
  }
}

image

6.8 排序

image

6.9 范圍篩選

image

默認值都為true,包含邊界值 "include_lower" : false 不包含下邊界 "include_upper" : false 不包含上邊界

命令行式API操作

2.xx

curl -XPUT localhost:9200/lib -d'{"number_of_replicas": 1}'

6.xx

curl -X PUT "localhost:9200/lib/" -H 'Content-type: application/json' -d '
{
    "settings" : {
        "number_of_shards" : 5,
        "number_of_replicas" : 1
    }
}
'

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM