Rest:Representational State Transfer
document文檔數(shù)據(jù)導(dǎo)入到es集群
put更新
主從(粗細(xì))散列分布,絕不能放在1個節(jié)點(diǎn)上
file
segment(段,多個document組成)
document(一條記錄,一個對象實(shí)例)
field(對象的屬性)
term(項(xiàng),分詞之后的詞條)
CURL命令
在命令行下訪問url的一個工具(理解為瀏覽器)
可以簡單實(shí)現(xiàn)常見的get/post請求
-X 指定http請求的方法:HEAD,GET,POST,PUT,DELETE
-d 指定要傳輸?shù)臄?shù)據(jù)
PUT和POST都可做創(chuàng)建和修改更新,就看id是否存在
# 建立索引庫
curl -XPUT http://192.168.118.102:9200/appke/
# 刪除索引庫
curl -XDELETE http://192.168.118.102:9200/test2/
# 創(chuàng)建document,添加數(shù)據(jù)自動創(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" ]
}'
# 添加屬性,動態(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"
}'
# 更新,下面都有問題
# 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" ]
}'
# 錯誤? 找不到句柄,參數(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來獲取數(shù)據(jù):(?pretty有縮進(jìn))
curl -XGET http://192.168.118.102:9200/appke/employee/1?pretty
#根據(jù)field來查詢數(shù)據(jù):
curl -XGET http://192.168.118.102:9200/appke/employee/_search?q=first_name="bin"
# 根據(jù)field來查詢數(shù)據(jù):match,查詢條件封裝!
curl -XGET http://192.168.118.102:9200/appke/employee/_search?pretty -d '
{
"query":
{"match":
{"first_name":"bin"}
}
}'
#對多個field發(fā)起查詢:multi_match,匹配多個字段
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"
}
}
}'
多個term對多個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個從,主默認(rèn)5個 5x(1+2)=15
curl -XPUT 'http://192.168.118.102:9200/test2/' -d'{"settings":{"number_of_replicas":2}}'
# 3個主,3個從 ,3x(1+3)=12,總共只有3個節(jié)點(diǎn),最多只能有2個從,即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ù)庫的數(shù)據(jù)對比,叫法變了
REST的操作分為以下幾種
-
GET:獲取對象的當(dāng)前狀態(tài); -
PUT:改變對象的狀態(tài); -
POST:創(chuàng)建對象; -
DELETE:刪除對象; -
HEAD:獲取頭信息

ES內(nèi)置的REST接口