ES 语法(2)
申明:此文章是早期学习的时候从其他博主的博文中整理而来的,但不记得是哪位博主的了,无法提供原文链接,见谅!!!
动态的 mapping es 或根据第一次存入的数据,动态的决定这个字段的 mapping 类型,并且决定索引行为,后面类型不符合就没法存入,mapping 里面的 类型不能修改,只能添加新的
PUT /test2/t/1 { "age":1, "name":"name", "bri":"2017-09-09", "isDel":true, "amount":0.1 }
指定 mapping 只能给新的索引指定 ,或者 个新的字段指定
PUT /test2/_mapping/t { "properties": { "age": { "type": "long" }, "amount": { "type": "float" }, "bri": { "type": "date" }, "isDel": { "type": "boolean" }, "name": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }
指定 索引的 setting
PUT test3 { "settings": { "index": { "number_of_shards": "3", "number_of_replicas": "1" } } }
PUT test4/_settings { "index": { "number_of_replicas": "4" } }
注:number_of_shards 不能修改
mapping 里面 keyword 的可以指定 text 的子类型,如果 字段类型是 json ,那么这个字段的类型就是 object ,或者说是docment 这时候 mapping 里面是 映射了一个property
"name": { "type": "text", "fields": { "keyword": { "type": "keyword" } } }
给索引取一个名字,取别名
put user/_aliases/user_al
或者:
POST /_aliases { "actions": [ { "add": { "index": "user", "alias": "user_a" } }, { "add": { "index": "user", "alias": "user_b" } } ] }
注: 对个索引可以使用同一个别名
查询 别名:
GET /user/_alias
删除别名 :
POST /_aliases { "actions": [ { "remove": { "index": "user", "alias": "user_a" } }, { "remove": { "index": "test", "alias": "user_b" } } ] }
自定义 分词器
PUT /user5 { "settings":{ "analysis": { "char_filter": { "my_char_filter":{ "type":"mapping", "mappings":["&=> and"] } }, "filter": { "my_filter":{ "type":"stop", "stopwords":["the","a"] } }, "analyzer": { "my_analyzer":{ "type":"custom", "char_filter":[ "my_char_filter" ], "filter":["my_filter"], "tokenizer":"standard" } } } } }
解释:定义了一个 char_filter 名叫 my_char_filter,类型是 mapping 把& 转成 and
定义了一个 filter 名叫 my_filter ,类型是停用词,把 the ,a 去掉
定义了一个分析器 名叫 my_analyzer, 类型是自定义,它使用了 char_filter 是 my_char_filter ,它使用的 filter 是 my_filter ,它使用的 分词器是 标准分词器
查看 一段文本是在某个分词器上是怎么分词的:
GET /user/_analyze { "analyzer": "standard", "text": " a dog is in the house" }
给指定 字段指定指定的分词器:
PUT /user3/_mapping/student { "properties":{ "name":{ "type":"text", "analyzer":"standard" } } }
dynamic 策略 三种 ,true (遇到陌生字段就 dynamic mapping ),false(遇到陌生字段就忽略) ,strict(遇到陌生字段就报错)
document 写入原理
每次写请求写入到 内存 buffer ,当 写到一定程度的时候,刷新,buffer 写到 lucene 的 segment,大概1 秒一次。segment 会吧数据写到 oscache ,然后执行 fsysc 命令吧 欧式chache 写到disk中。删除的时候是加删除,在index segment 中创建一个.del文件,在一定时候index segment 合并的时候,会删除这个del文件。更新,先执行删除,然后在执行插入。值得注意的是,没个一秒 buffer 提交一次,并且产生一个新的 segment,而且,这时候会出发 segment 到 oscache 的提交。数据提交到 os cache 的 以后就可以搜索到了,所以这就是 1 秒 近实时的原因。可以给index指定刷新的时间。 refresh_interval,并且 es 还会写 tranlog(写buffer的同时)文件,这个文件可以避免丢失。每次提交会创建一个tranlog 文件,提交完成会删除原来的 tranlog 文件。在提交以后记录会写到新的 tranlog 中
如果 字段类型是 json ,那么这个字段的类型就是 object ,或者说是docment 这时候 mapping 里面是 映射了一个property
本文来自博客园,作者:Vermeer,转载请注明原文链接:https://www.cnblogs.com/chxlay/p/15114991.html
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号