1. 程式人生 > >2.Elasticsearch增、刪、改、查操作

2.Elasticsearch增、刪、改、查操作

銘毅天下,原文地址:blog.csdn.net/laoyang360 https://blog.csdn.net/wojiushiwo987/article/details/51931981

引言:

對於剛接觸ES的童鞋,經常搞不明白ES的各個概念的含義。尤其對“索引”二字更是與關係型資料庫混淆的不行。本文通過對比關係型資料庫,將ES中常見的增、刪、改、查操作進行圖文呈現。能加深你對ES的理解。同時,也列舉了kibana下的圖形化展示。

ES Restful API GET、POST、PUT、DELETE、HEAD含義: 
1)GET:獲取請求物件的當前狀態。 
2)POST:改變物件的當前狀態。 
3)PUT:建立一個物件。 
4)DELETE:銷燬物件。 
5)HEAD:請求獲取物件的基礎資訊。

Mysql與Elasticsearch核心概念對比示意圖 
這裡寫圖片描述 
以上表為依據, 
ES中的新建文件(在Index/type下)相當於Mysql中(在某Database的Table)下插入一行資料。

1、新建文件(類似mysql insert插入操作)

http://localhost:9200/blog/ariticle/1 put
{
"title":"New version of Elasticsearch released!",
"content":"Version 1.0 released today!",
"tags":["announce","elasticsearch","release"]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

建立成功如下顯示:

{

- "_index": "blog",
- "_type": "ariticle",
- "_id": "1 -d",
- "_version": 1,
- "_shards": {
    - "total": 2,
    - "successful": 1,
    - "failed": 0
- },
- "created": true

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

這裡寫圖片描述

2、檢索文件(類似mysql search 搜尋select*操作)

檢索結果如下:

{

- "_index": "blog",
- "_type": "ariticle",
- "_id":
"1",
- "_version": 1, - "found": true, - "_source": { - "title": "New version of Elasticsearch released!", - "content": "Version 1.0 released today!", - "tags": [ - "announce" - , - "elasticsearch" - , - "release" - ] - } }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

如果未找到會提示:

{

- "_index": "blog",
- "_type": "ariticle",
- "_id": "11",
- "found": false

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

查詢全部文件如下: 
這裡寫圖片描述 
具體某個細節內容檢索, 
查詢舉例1:查詢cotent列包含版本為1.0的資訊。 
http://localhost:9200/blog/ 
_search?pretty&q=content:1.0

{

- "took": 2,
- "timed_out": false,
- "_shards": {
    - "total": 5,
    - "successful": 5,
    - "failed": 0
- },
- "hits": {
    - "total": 1,
    - "max_score": 0.8784157,
    - "hits": [
        - {
            - "_index": "blog",
            - "_type": "ariticle",
            - "_id": "6",
            - "_score": 0.8784157,
            - "_source": {
                - "title": "deep Elasticsearch!",
                - "content": "Version 1.0!",
                - "tags": [
                    - "deep"
                    - ,
                    - "elasticsearch"
                - ]
            - }
        - }
    - ]
- }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

查詢舉例2:查詢書名title中包含“enhance”欄位的資料資訊: 
[[email protected] ~]# curl -XGET 10.200.1.121:9200/blog/ariticle/_search?pretty -d ‘

> { "query" : {
> "term" :
> {"title" : "enhance" }
> }
> }'
{
  "took" : 189,
  "timed_out" : false,
  "_shards" : {
  "total" : 5,
  "successful" : 5,
  "failed" : 0
  },
  "hits" : {
  "total" : 2,
  "max_score" : 0.8784157,
  "hits" : [ {
  "_index" : "blog",
  "_type" : "ariticle",
  "_id" : "4",
  "_score" : 0.8784157,
  "_source" : {
  "title" : "enhance Elasticsearch!",
  "content" : "Version 4.0!",
  "tags" : [ "enhance", "elasticsearch" ]
  }
  }, {
  "_index" : "blog",
  "_type" : "ariticle",
  "_id" : "5",
  "_score" : 0.15342641,
  "_source" : {
  "title" : "enhance Elasticsearch for university!",
  "content" : "Version 5.0!",
  "tags" : [ "enhance", "elasticsearch" ]
  }
  } ]
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

查詢舉例3:查詢ID值為3,5,7的資料資訊: 
[[email protected] ~]# curl -XGET 10.200.1.121:9200/blog/ariticle/_search?pretty -d ‘

{ "query" : {
"terms" :
{"_id" : [ "3", "5", "7" ] }
}
}'
{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
  "total" : 5,
  "successful" : 5,
  "failed" : 0
  },
  "hits" : {
  "total" : 3,
  "max_score" : 0.19245009,
  "hits" : [ {
  "_index" : "blog",
  "_type" : "ariticle",
  "_id" : "5",
  "_score" : 0.19245009,
  "_source" : {
  "title" : "enhance Elasticsearch for university!",
  "content" : "Version 5.0!",
  "tags" : [ "enhance", "elasticsearch" ]
  }
  }, {
  "_index" : "blog",
  "_type" : "ariticle",
  "_id" : "7",
  "_score" : 0.19245009,
  "_source" : {
  "title" : "deep Elasticsearch for university!",
  "content" : "Version 2.0!",
  "tags" : [ "deep", "elasticsearch", "university" ]
  }
  }, {
  "_index" : "blog",
  "_type" : "ariticle",
  "_id" : "3",
  "_score" : 0.19245009,
  "_source" : {
  "title" : "init Elasticsearch for university!",
  "content" : "Version 3.0!",
  "tags" : [ "initialize", "elasticsearch" ]
  }
  } ]
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

3、更新文件(類似mysql update操作)

更新後結果顯示: 
{

  • “_index”: “blog”,
  • “_type”: “ariticle”,
  • “_id”: “1”,
  • “_version”: 2,
  • “_shards”: { 
    • ”total”: 2,
    • “successful”: 1,
    • “failed”: 0
  • }

}

{

- "_index": "blog",
- "_type": "ariticle",
- "_id": "1",
- "_version": 2,
- "found": true,
- "_source": {
    - "title": "New version of Elasticsearch released!",
    - "content": "new version 2.0 20160714",
    - "tags": [
        - "announce"
        - ,
        - "elasticsearch"
        - ,
        - "release"
    - ]
- }

}
`![這裡寫圖片描述](https://img-blog.csdn.net/20160717132407353)``

注意更新文件需要在elasticsearch_win\config\elasticsearch.yml下新增以下內容:
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

script.groovy.sandbox.enabled: true 
script.engine.groovy.inline.search: on 
script.engine.groovy.inline.update: on 
script.inline: on 
script.indexed: on 
script.engine.groovy.inline.aggs: on 
index.mapper.dynamic: true

4、刪除文件(類似mysql delete操作)

{

- "found": true,
- "_index": "blog",
- "_type": "ariticle",
- "_id": "8",
- "_version": 2,
- "_shards": {
    - "total": 2,
    - "successful": 1,
    - "failed": 0
- }

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

這裡寫圖片描述

5、Kibana視覺化分析

5.1、在索引blog上查詢包含”university”欄位的資訊。

這裡寫圖片描述

5.2、Kibana多維度分析

這裡寫圖片描述

——————————————————————————————————

相關推薦

shell指令碼操作mysql資料庫,使用mysql的-e引數可以執行各種sql的(建立,刪除,)等各種操作

來源:http://blog.163.com/xychenbaihu@yeah/blog/static/13222965520114116289991/ mysql  -hhostname -Pport -uusername -ppassword  -e  相關mysql的

asp.net core 2.1 dotnet(三)EF.core 的

1.呼叫方式:    增加引用:          using Microsoft.EntityFrameworkCore;         using Newtonsoft

GreenDao3.2使用詳解(,升級)

首先看一下效果圖: 專案結構如下圖所示: 第一步:在build中新增配置如下: projet 目錄下的build.gradle dependencies { classpath 'org.greenrobot:greendao-gradl

dict的

date 關聯 print none 必須 數據類型 相同 一個 code dict是無序的 ,數據關聯性強,鍵值對,唯一一個個映射的數據類型 字典的鍵必須是可哈希的數據類型 (字符串,數字,bool,元祖)並且是唯一的. 不可哈希的:(列表,字典) dict的增 1

Javascript操作Cookie(

time() add return jna mts cap 關閉 nbsp expire 1 //1. 獲得指定名稱為ObjName的Cookie的值 2 function getCookie(ObjName){ 3 var arrStr = documen

MySql cmd下的學習筆記 —— 有關表的操作

strong .com nsh utf str tab 主鍵 test har (知識回顧) 連接數據庫 mysql -uroot -p111 先建立一個新庫 create database test1; use test1; 由於今天的主要內容是表的操作,建立表的詳細過

mysql基本功能

增 ==》 insert into 庫.表(欄位名列表) values(值列表); mysql> create table meinvdb.mm(-> id int(4) not null primary key,-> name varchar(18) not null-> );Que

mysql基本功能

cat dup pda key null cte insert value creat 增 ==》 insert into 庫.表(字段名列表) values(值列表); mysql> create table meinvdb.mm(-> id

MySQL基礎操作

一,SQL語言概述1,SQL語言是關係型資料庫的標準語言,用於維護管理資料庫,如資料查詢,資料更新,訪問控制,物件管理等功能。 2,建表 這是需要掌握的。(1)#Show databases; 檢視資料庫裡所有的小資料庫名。 show看 databases 資料庫小庫 (2)#Create databa

mybatis的傳統的實現

3.2.1、儲存使用者 <insert id="saveUser" parameterType="com.atguigu.mybatis.pojo.User"> insert into t_user(`last_name`,`sex`) valu

Mapper介面方式的mybatis的實現

4.1、Mapper介面程式設計的命名習慣Mapper介面方式的程式設計,需要先有一個介面。這個介面的命名一般是xxxxMapper。 比如: User模組的Mapper,介面命名為UserMapper。 Book模組的Mapper,介面命名為BookMappe

java連結mysql以及對資料庫的

package com.jdbcdemo; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManager; import java.sql.PreparedStateme

python第四天課程:列表(),元祖

''' #1.增加 append insert li = ['alex',[1,2,3],'wusir','egon','女神','taibai'] li.append('日天') print(li) li.append(1) print(li) while 1: name = input('請

Java中List的

package Colection; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; //備選課程類 public class L

斷電導致oracle的ORA-01207錯誤完全解決辦法(重做日誌檔案(redo log files)管理(,切))

彙總整理一下有關重做日誌檔案(redo log files)管理相關的操作(增,刪,改,查,切)。供參考。1.當前日誌相關資訊[email protected]> select * from v$log;    GROUP#    THREAD#  SEQUENCE#      BYTES  

表的完整語法( 子查詢 )

多行 教學 pan 比較 nbsp 匹配 字段 values 數據 表的完整語法增刪該查 表的完整 增 語法 1.所有數據按順序插入 insert [into] 表名 values (值1,……值n),[值1,……值n] 2.指定字段匹配插入,可以任意順序

SQL server中常見的操作

--增-- /*增加列*/ alter table 表名 add 列名 varchar(20) check(你的約束條件); 如:在學生情況表中增加一個Email列,要求檢查輸入的是否為Email; alter table 學生情況表 add Email varchar

基於SpringMVC框架,完成使用者的,以及json資料處理

package org.ksea.controller; import java.io.File; import java.io.IOException; import java.util.List; import javax.servlet.http.HttpServletRequest; import j

2.Elasticsearch操作

銘毅天下,原文地址:blog.csdn.net/laoyang360 https://blog.csdn.net/wojiushiwo987/article/details/51931981引言:對於剛接觸ES的童鞋,經常搞不明白ES的各個概念的含義。尤其對“索引”二字更是與

MySQL資料庫中表記錄的操作

來源:Java聯盟 好的各位小夥伴~ 今天我們要了解的就是關於 MySQL資料庫中 有關於表記錄的操作 修改表記錄 插入表記錄 語法: 向表中插入某些列 insert into 表 (列名1,列名2,列名3...) values  (值1,值2,值3.