es 的資料操作

2022-03-15 12:43:04 字數 2180 閱讀 3354

一、es資料的操作

1.建立索引

1)語法

put /
2)示例
put /index

curl -xput ''

2.建立資料

1)資料結構

es儲存三個必要構成

_index

_type

_id

構成

說明_index

索引(資料儲存的地方)

_type

型別(資料對應類)

_id資料的唯一標識

2)語法

put //_doc/<_id>

post //_doc/

put //_create/<_id>

post //_create/<_id>

index:索引的名稱,如果索引不存在,會自動建立

_doc:型別

_id:唯一標識,可以手動指定,也可以自動生成

3)使用自定義id插入資料
put /index/_doc/1

#該方式企業應用較少

1.需要修改id的值

2.指定id插入資料時,es會先拿著指定的id去對比一遍所有資料,看看有沒有相同值

4)使用隨機id插入資料
post /index/_doc/

5)新增字段指定id
post /index/_doc/

3.查詢資料

1)簡單查詢

#查詢所有索引的(資訊)

get /_all

get _all

#檢視所有索引的(資料)

get /_all/_search

#檢視指定索引的資訊

get /teacher

#檢視指定索引的資料

get /teacher/_search

#檢視索引中指定的資料

get /teacher/user/2

get /teacher/user/1m-gghyb5ia7o7wd9dpk

2)單條件查詢

1>方法一:

get /teacher/_search

}}}

2>方法二:
get /teacher/_search

}}

3>方法三:
get /teacher/_search

}}#指定條件可以使用term也可以使用match,term搜尋資料時不進行分詞,適合進行精確查詢,match搜尋時進行分詞適用於全文檢索

3)多條件查詢

1>must查詢(and)

#多個查詢條件必須全部滿足  &

get /teacher/_search}},

}}]}

}}

2>filter查詢(and)
#跟must作用一樣,但是速度要比must快一點

get /teacher/_search},}

]}

}}

3>should查詢(or)
#多條件查詢時,符合其中乙個條件就可以  |

get /teacher/_search}},

}}]}

}}

4)must_not(not)
get /teacher/_search}},

}}]}

}}

5)must和should結合使用
#查詢年齡是21或者年齡是18歲並且名字是lizhenglin的資料

get /teacher/_search}},

}},}}

]}}]

}}}

4.修改資料
#修改資料通過_id進行修改,修改資料是,除了要修改的字段意外,其他的字段也要全部寫上

put /teacher/user/9g-fhxyb5ia7o7wdedoh

5.刪除資料
#刪除指定資料,通過_id進行選擇刪除

delete /teacher/user/9g-fhxyb5ia7o7wdedoh

#刪除索引

delete /teacher

es資料操作入門

一 es資料儲存簡單介紹 1.概念解釋 index 索引,它是單個資料庫的同義詞。type 索引型別,它是單個資料表的同義詞。document 文件,它是單條資料記錄的同義詞。理論上乙個index可以包含多個type,但是在實際應用中一般乙個index只包含乙個type,若包含多個type,容易造成...

ES資料庫相關操作

es資料庫的應用 最近的專案中,es集群分三個節點安裝,乙個主節點,兩個副節點。目前我們的使用場景主要是儲存流量日誌資料,針對不同的日誌型別,索引按天建立,例如skyeye tcpflow 20191001 skyeye udpflow 20191002。es分片的作用,為了讓所有資料均衡的儲存在集...

ES的基礎操作

分詞器 ik max word post analyze 分詞器 ik smart post analyze 索引庫操作 建立索引庫 put ithe 檢視索引庫 get ithe 刪除索引庫 delete ithe 檢視索引庫 get ithe 需求1 建立type表 方式一 先建庫,再建type...