ElasticSearch之倒排索引-索引操作-映射管理
ElasticSearch-倒排索引
# es的存储原理,为什么能实现大数据量的快速检索,全文检索 #倒排索引源于实际应用中需要根据属性的值来查找记录,这种索引表中的每一个项都包括一个属性值和具有该属性值的各记录的地址。由于不是由记录来确定属性值,而是由属性值来确定记录的位置,因而成为倒排索引。带有倒排索引的文件我们称之为倒排索引文件,简称倒排文件 属性值确定记录位置的索引方式称之为倒排索引 根据文章内容中的关键字建立索引称之为倒排索引 # keyword和text类型都是字符串类型 keyword不进行分词,直接建立索引 text类型进行分词,对分词建立索引
ElasticSearch-索引操作
# 增 PUT wql { "settings": { "index":{ "number_of_shards":5, "number_of_replicas":1 } } } # 删 DELETE wql # 查 GET wql/_settings # 查lqz索引的配置 GET wql/_settings GET _all/_settings # 查所有索引的配置 GET _settings GET wql,wql/_settings# 查lqz,lqz1索引的配置 # 改(一般不改) 分片数量,副本数量 PUT wql1/_settings { "number_of_replicas": 2 # 副本数量改为2 }
ElasticSearch-映射管理
# es中类型---》mysql的表 # mysql中有建表语句----》es中就是映射管理---》即便没有类型,文档可以直接插入 # 映射:预先定义字段的类型及相关属性 # es字段类型 string类型:text,keyword # 区别 数字类型:long,integer,short,byte,double,float java:byte,short,interger,long float,double go语言中:int8 int16 int32 int64 float32,float64 日期类型:data 布尔类型:boolean binary类型:binary 复杂类型:object(实体,对象,字典),nested(列表) geo类型:geo-point,geo-shape(地理位置) 专业类型:ip,competion(搜索建议) # es字段类型属性 -是否可以为空:所有类型 -字符串类型:analyzer 指定什么分词器 -日期类型:format # 建立类型 # 6.x及以前版本------》books索引名字---》mapping下还有book,类型名(表名) PUT books { "mappings": { "book":{ "properties":{ "title":{ "type":"text", "analyzer": "ik_max_word" }, "price":{ "type":"integer" }, "addr":{ "type":"keyword" }, "company":{ "properties":{ "name":{"type":"text"}, "company_addr":{"type":"text"}, "employee_count":{"type":"integer"} } }, "publish_date":{"type":"date","format":"yyy-MM-dd"} } } } } # 7.x及以上,6.x以后,强制一个索引下只能有一个类型,叫_doc (一个数据库只能建一个表) PUT books { "mappings": { "properties":{ "title":{ "type":"text" }, "price":{ "type":"integer" }, "addr":{ "type":"keyword" }, "company":{ "properties":{ "name":{"type":"text"}, "company_addr":{"type":"text"}, "employee_count":{"type":"integer"} } }, "publish_date":{"type":"date","format":"yyy-MM-dd"} } } } # 插入文档 PUT books/_doc/1 { "title":"大头儿子小偷爸爸", "price":100, "addr":"北京天安门", "company":{ "name":"我爱北京天安门", "company_addr":"我的家在东北松花江傻姑娘", "employee_count":10 }, "publish_date":"2019-08-19" } #测试数据2 PUT books/_doc/2 { "title":"白雪公主和十个小矮人", "price":"99", #写字符串会自动转换 "addr":"黑暗森里", "company":{ "name":"我的家乡在上海", "company_addr":"朋友一生一起走", "employee_count":10 }, "publish_date":"2018-05-19" } PUT books/_doc/3 # 这个也可以存 { "age":"白雪公主和十个小矮人", "name":'lqz' } ## 查看映射 GET books/_mapping

浙公网安备 33010602011771号