目錄
索引index
定制分詞器
Type底層結(jié)構(gòu)及棄用原因
定制 dynamic mapping
定制dynamic mapping template 動態(tài)映射模板
零停機(jī)重建索引
生產(chǎn)環(huán)境應(yīng)該度別名數(shù)據(jù)
索引index
Put /index
Stings 分片
Mapping 映射
Aliases 別名
增加
Put my_index2 { ?????? "settings":{ ?????? ?? "number_of_shards":3, ?????? ?? "number_of_replicas":1 ? }, ? "mappings":{ ??? "properties":{ ????? "name":{"type":"text"} ??? } ? }, ? "aliases":{ ??? "default_index":{} ??? ? } } |
Default_index 別名 也可以用來查詢
Get default_index/_doc/1
獲取索引信息
Get myindex
修改索引
?
刪除必須設(shè)置索引名 防止 delete /_all 刪除全部索引
?
定制分詞器
delete my_inde
#定制分詞器
put /my_index
{
? "settings":{
??? "analysis":{
????? "analyzer":{
??????? "es_std":{
????????? "type":"standard",
????????? "stopwords":"_english_"
??????? }
????? }
??? }
? }
}
#測試標(biāo)準(zhǔn)分詞器
get /my_index/_analyze
{
? "analyzer":"standard",
? "text":"a dog is in the house helloword"
}
#測試自定義分詞器
get /my_index/_analyze
{
? "analyzer":"es_std",
? "text":"a dog is in the house helloword"
}
delete /my_index
#定制分詞器詳細(xì)過程
#char_filter 預(yù)處理階段 & 轉(zhuǎn)and 分詞器
#filter 停用詞策略 the a 取消分詞
#analyzer 定制分詞器
# "char_filter":["html_strip","&_to_and"],? 標(biāo)簽 分詞器
put /my_index
{
? "settings":{
??? "analysis":{
????? "char_filter":{
??????? "&_to_and":{
????????? "type":"mapping",
????????? "mappings":["&=> and"]
??????? }
????? },
????? "filter":{
??????? "my_stopwords":{
????????? "type":"stop",
????????? "stopwords":["the","a"]
??????? }
????? },
????? "analyzer":{
??????? "my_analyzer":{
????????? "type":"custom",
????????? "char_filter":["html_strip","&_to_and"],
????????? "tokenizer":"standard",
????????? "filter":["lowercase","my_stopwords"]
??????? }
????? }
??? }
? }
}
#測試
#& 變成 and? the 消失? 測試成功
get /my_index/_analyze
{
? "analyzer":"my_analyzer",
? "text":"a dog is & in the house helloword"
}
Type底層結(jié)構(gòu)及棄用原因
預(yù)計Es 9 后徹底刪除
Type 是索引中區(qū)分?jǐn)?shù)據(jù)類型的
Es 存儲type不同機(jī)制
?
對應(yīng)倆種數(shù)據(jù)類型 存儲方式
?
Es 底層存儲結(jié)構(gòu)
?
每條信息需要記錄,浪費(fèi)很多存儲空間,統(tǒng)一索引下 有很多type沒有值導(dǎo)致大量空值導(dǎo)致浪費(fèi)空間
所以預(yù)計在es9后徹底刪除這個字段
定制 dynamic mapping
定制 dynamic策略
#動態(tài)mapping映射狀態(tài) false 未設(shè)置字段不進(jìn)入倒排索引
#沒有定義的false 字段不會進(jìn)入倒排索引
#有定義的按照定義的 會進(jìn)入倒排索引
#可以插入新字段但是不會進(jìn)入倒排索引,定義的會進(jìn)入倒排索引
put myindex
{
? "mappings":{
??? "dynamic":false,
??? "properties":{
??????? "title":{"type":"text"},
??????? "address":{
????????? "type":"object",
????????? "dynamic":true
??????? }
??? }
???
? }
}
沒有動態(tài)映射的,通過中間詞是無法查詢的需要全文檢索才可以
#必須標(biāo)準(zhǔn)字段,多余字段會報錯無法存入
?"dynamic":strict,
#關(guān)閉日期探測,自動變成text類型“date_detection”:false
Put /myindex
{
“mappings”:{
?????? “date_detection”:false
}
}
Get /myindex/_maping
自定義日期格式
Put myindex
{
?????? "mappings":{
????????????? "dynamic_date_formats":["yyyy-MM-dd"]
}
}
傳來string 轉(zhuǎn)換long 或float"numeric_detection":true
delete myindex
Put myindex
{
?????? "mappings" :{
????????????? "numeric_detection":true
}
}
Put /myindex/_doc/1
{
"my_float":"1.0",
"my_long":"1"
}
get myindex/_doc/1
get /myindex/_mapping
?
定制dynamic mapping template 動態(tài)映射模板
delete myindex
#創(chuàng)建動態(tài)映射模板如果命中規(guī)則,使用此模板英文分詞器
#*_en 結(jié)尾的使用text 存 英文分詞器
put /myindex
{
? "mappings":{
??? "dynamic_templates":[{
????? "en":{
??????? "match":"*_en",
??????? "match_mapping_type":"string",
??????? "mapping":{
????????? "type":"text"
????????? ,"analyzer":"english"
??????? }
????? }
??? }]
? }
}
put /myindex/_doc/1
{"te":"this is my xx_en"}
put /myindex/_doc/4
{"tccsssse":"this is 中文my? "}
get myindex/_mapping
匹配規(guī)則
Match 屬于什么
Unmatch 不屬于什么
Match_mapping_type 屬于什么類型
Path_match? 路徑匹配 *.xx?
Path_unmatch 路徑不匹配
?
Norms false 指標(biāo)評分因素
?
零停機(jī)重建索引
?
在線上運(yùn)行的項(xiàng)目,發(fā)現(xiàn)不滿足要求,創(chuàng)建新索引把舊數(shù)據(jù)放到新索引中去,從而實(shí)現(xiàn)重建索引
拷貝索引數(shù)據(jù)時間,則是停機(jī)不太好
//愿索引 date
Put /my_index
{
“mappings”:{
?????? “name”:{
????????????? “type:”date”
}
}
}
//設(shè)置讀取位置
Put /my_index/_alias/prod_index
//新索引
Put /my_index_new
{
“mappings”:{
?????? “name”:{
????????????? “type:”text”
}
}
}
//切換別名值 程序讀取別名
Post /_aliases
{
?????? “actions”:[
????????????? {“remove”:{“index:”my_index”,”alias”:”prod_index”}}
{“add”:{“index:”my_index_new”,”alias”:”prod_index”}}
]
}
生產(chǎn)環(huán)境應(yīng)該度別名數(shù)據(jù)
?
ok文章來源:http://www.zghlxwxcb.cn/news/detail-460524.html
持續(xù)更新文章來源地址http://www.zghlxwxcb.cn/news/detail-460524.html
到了這里,關(guān)于es elasticsearch 九 索引index 定制分詞器 type結(jié)構(gòu)后期棄用原因 定制動態(tài)映射 動態(tài)映射模板 零停機(jī)重建索引的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!