Rest:Representational State Transfer
document文檔數(shù)據(jù)導(dǎo)入到es集群
put更新
主從(粗細(xì))散列分布,絕不能放在1個(gè)節(jié)點(diǎn)上
file
segment(段缕棵,多個(gè)document組成)
document(一條記錄孵班,一個(gè)對(duì)象實(shí)例)
field(對(duì)象的屬性)
term(項(xiàng)涉兽,分詞之后的詞條)
CURL命令
在命令行下訪問(wèn)url
的一個(gè)工具(理解為瀏覽器)
可以簡(jiǎn)單實(shí)現(xiàn)常見的get/pos
t請(qǐng)求
-X
指定http請(qǐng)求的方法:HEAD
,GET
,POST
,PUT
,DELETE
-d
指定要傳輸?shù)臄?shù)據(jù)
PUT
和POST
都可做創(chuàng)建和修改更新
,就看id
是否存在
# 建立索引庫(kù)
curl -XPUT http://192.168.118.102:9200/appke/
# 刪除索引庫(kù)
curl -XDELETE http://192.168.118.102:9200/test2/
# 創(chuàng)建document篙程,添加數(shù)據(jù)自動(dòng)創(chuàng)建id
curl -XPOST http://192.168.118.102:9200/appke/employee -d '
{
"first_name" : "bin",
"age" : 33,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music"]
}'
curl -XPOST http://192.168.118.102:9200/appke/employee -d '
{
"first_name" : "bin guo",
"age" : 47,
"about" : "I love to fitness",
"interests": [ "fishing", "music"]
}'
curl -XPOST http://192.168.118.102:9200/appke/employee/2 -d '
{
"first_name" : "bin",
"age" : 45,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ]
}'
# 添加屬性枷畏,動(dòng)態(tài)類的增值
curl -XPOST http://192.168.118.102:9200/appke/employee -d '
{
"first_name" : "pablo2",
"age" : 33,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ],
"sex": "man"
}'
# 指定id
curl -XPOST http://192.168.118.102:9200/appke/employee/222 -d '
{
"first_name" : "pablo2",
"age" : 35,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ],
"sex": "man"
}'
# 更新,下面都有問(wèn)題
# appke/employee/1 1是id虱饿,隨便的拥诡,相當(dāng)于增加
curl -XPUT http://192.168.118.102:9200/appke/employee/1 -d '
{
"first_name" : "god bin",
"last_name" : "pang",
"age" : 42,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ]
}'
# 錯(cuò)誤? 找不到句柄,參數(shù)沒給全
curl -XPUT http://192.168.118.102:9200/appke/employee -d '
{
"first_name" : "god bin",
"last_name" : "bin",
"age" : 45,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ]
}'
# 修改更新
curl -XPUT http://192.168.118.102:9200/appke/employee/1 -d '
{
"first_name" : "god bin",
"last_name" : "pang",
"age" : 40,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ]
}'
document
獲取數(shù)據(jù)
#根據(jù)document的id來(lái)獲取數(shù)據(jù):(?pretty有縮進(jìn))
curl -XGET http://192.168.118.102:9200/appke/employee/1?pretty
#根據(jù)field來(lái)查詢數(shù)據(jù):
curl -XGET http://192.168.118.102:9200/appke/employee/_search?q=first_name="bin"
# 根據(jù)field來(lái)查詢數(shù)據(jù):match氮发,查詢條件封裝渴肉!
curl -XGET http://192.168.118.102:9200/appke/employee/_search?pretty -d '
{
"query":
{"match":
{"first_name":"bin"}
}
}'
#對(duì)多個(gè)field發(fā)起查詢:multi_match,匹配多個(gè)字段
curl -XGET http://192.168.118.102:9200/appke/employee/_search?pretty -d '
{
"query":
{"multi_match":
{
"query":"bin",
"fields":["last_name","first_name"],
"operator":"and"
}
}
}'
多個(gè)term對(duì)多個(gè)field發(fā)起查詢:bool(boolean)
# 組合查詢爽冕,must, must_not, should
# must + must : 交集
# must +must_not :差集
# should+should : 并集
curl -XGET http://192.168.118.102:9200/appke/employee/_search?pretty -d '
{
"query":
{"bool" :
{
"must" :
{"match":
{"first_name":"bin"}
},
"must" :
{"match":
{"age":33}
}
}
}
}'
curl -XGET http://192.168.118.102:9200/appke/employee/_search?pretty -d '
{
"query":
{"bool" :
{
"must" :
{"match":
{"first_name":"bin"}
},
"must_not" :
{"match":
{"age":33}
}
}
}
}'
curl -XGET http://192.168.118.102:9200/appke/employee/_search?pretty -d '
{
"query":
{"bool" :
{
"must_not" :
{"match":
{"first_name":"bin"}
},
"must_not" :
{"match":
{"age":33}
}
}
}
}'
##查詢first_name=bin的仇祭,或者年齡在20歲到33歲之間的
curl -XGET http://192.168.118.102:9200/appke/employee/_search -d '
{
"query":
{"bool" :
{
"must" :
{"term" :
{ "first_name" : "bin" }
}
,
"must_not" :
{"range":
{"age" : { "from" : 20, "to" : 33 }
}
}
}
}
}'
修改配置
# 2個(gè)從,主默認(rèn)5個(gè) 5x(1+2)=15
curl -XPUT 'http://192.168.118.102:9200/test2/' -d'{"settings":{"number_of_replicas":2}}'
# 3個(gè)主扇售,3個(gè)從 前塔,3x(1+3)=12,總共只有3個(gè)節(jié)點(diǎn)承冰,最多只能有2個(gè)從华弓,即3x(1+2)=9
curl -XPUT 'http://192.168.118.102:9200/test3/' -d'{"settings":{"number_of_shards":3,"number_of_replicas":3}}'
curl -XPUT 'http://192.168.118.102:9200/test4/' -d'{"settings":{"number_of_shards":6,"number_of_replicas":4}}'
curl -XPOST http://192.168.9.11:9200/appke/person/_mapping -d'
{
"person": {
"properties": {
"content": {
"type": "string",
"store": "no",
"term_vector": "with_positions_offsets",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"include_in_all": "true",
"boost": 8
}
}
}
}'
ES和關(guān)系型數(shù)據(jù)庫(kù)的數(shù)據(jù)對(duì)比,叫法變了
REST
的操作分為以下幾種
-
GET
:獲取對(duì)象的當(dāng)前狀態(tài)困乒; -
PUT
:改變對(duì)象的狀態(tài)寂屏; -
POST
:創(chuàng)建對(duì)象; -
DELETE
:刪除對(duì)象娜搂; -
HEAD
:獲取頭信息
ES內(nèi)置的REST接口