ElasticSearch字段属性个性化设置
字段常用属性设置1.index是否可以检索
index 字段是否可以被检索,取值true/false,默认true。#创建索引 PUT user_test_001 { "mappings":{ "properties":{ "id":{ "type":"integer", "index":false }, "name":{ "type":"text", "index":true } } } } #插入数据 PUT user_test_001/_create/1 { "id":"1001", "name":"william" } #检索 GET user_test_001/_search { "query": { "match": { "id": "1001" } } } #搜索提示:"failed to create query: Cannot search on field [id] since it is not #indexed." GET user_test_001/_search { "query": { "match": { "name": "william" } } }2.store 是否存储
es默认原始数据存储在_source里,其实也可以在lucene里面存储一份,通过此关键字控制取值,默认不存储,作用在字段上,很精细化。原始数据_source被禁用,也需要修改原始数据。当数据量大时,才可能用上该属性。 #创建索引 PUT user_test_001 { "mappings":{ "properties":{ "userId":{ "type":"integer", "store":true }, "name":{ "type":"text", "store": true }, "address":{ "type":"text", "store": false } } } } #插入数据 PUT user_test_001/_create/1 { "userId":"1001", "name":"william", "address":"深圳南山区" } #检索 GET user_test_001/_search { "stored_fields": ["userId","name"], "query": { "match_all": {} } }3.enabled 能否启用
设置字段是否需要被检索,作用在object,举例,先设置enabled: true,看看mapping # 设置mappings PUT user_test_001 { "mappings":{ "_source":{ "enabled":false } "properties":{ "id":{ "type":"integer", "index":false }, "name":{ "type":"text", "store": true }, "job":{ "type":"object", "enabled":true } } } } #查看索引
接下来enabled设置为false# 设置mappings PUT user_test_001 { "mappings":{ "_source":{ "enabled":false } "properties":{ "id":{ "type":"integer", "index":false }, "name":{ "type":"text", "store": true }, "job":{ "type":"object", "enabled":false } } } } #查看mapping. 发现字段类型为object类型的job的变化。 通过这种方式,可以扩展字段个数。 # 插入数据 PUT user_test_001/_create/1 { "id":"1001", "name":"william", "job":{ "company":"apple", "department":"software", "post":"java development" } } # 检索 GET user_test_01/_search { "query":{ "match":{ "id":"1" } } }4.doc_value 能否聚合排序
列式数据库存储。es数据存储,原始数据一份 # 设置mappings PUT user_test_001 { "mappings":{ "_source":{ "enabled":true }, "properties":{ "userId":{ "type":"integer", "doc_values":false }, "name":{ "type":"text", "doc_values": true }, "age":{ "type":"integer", "doc_values":true }, "hobby":{ "type":"text", "doc_values":false } } } } # 插入数据 PUT user_test_001/_create/1 { "userId":"1001", "name":"william", "age":18, "hobby":"唱歌、跳舞" } PUT user_test_001/_create/2 { "userId":"1001", "name":"john", "age":22, "hobby":"唱歌" } #排序 GET user_test_001/_search { "query":{ "match_all":{} }, "sort":[ { "userId":{ "order":"desc" } } ] } #报错不能根据userId进行排序,可以试试根据age #聚合 GET user_test_001/_search { "size":0, "aggs":{ "age_avg":{ "avg":{ "field":"age" } } } } 5.null_value 空值设置
对于聚合功能,需要设置默认值,若不设置,值为空,则会出现异常情况。与数据库不同的是,es并不会存储设置的默认空值,仅仅用来做索引检索。 PUT user_test_001 { "mappings":{ "_source":{ "enabled":true }, "properties":{ "userId":{ "type":"integer" }, "name":{ "type":"text" }, "income":{ "type":"integer", "null_value":0 } } } } PUT user_test_001/_doc/1 { "userId":"1001", "name":"william" } GET user_test_001/_search { "size":0, "aggs":{ "sum_income":{ "sum":{ "field": "income" } } } }6.properties 子对象字段约束PUT user_test_001 { "mappings": { "_source": { "enabled": true }, "properties": { "userId": { "type": "integer" }, "name": { "type": "text" }, "work": { "type": "object", "properties": { "company": { "properties": { "companyName": { "type": "keyword" }, "position": { "type": "keyword" } } }, "city": { "type":"object", "enabled":false } } } } } }
7.dynamic 子对象动态扩展
是否容许对象下面的属性自由扩展,严格限制子对象下面的字段行为。取值:true/false/strict,默认true PUT user_test_001 { "mappings": { "_source": { "enabled": true }, "properties": { "userId": { "type": "integer" }, "name": { "type": "text" }, "work": { "dynamic": "strict", "properties": { "company": { "properties": { "companyName": { "type": "keyword" }, "position": { "type": "keyword" } } }, "city": { "type":"object", "enabled":false } } } } } } PUT user_test_001/_doc/1 { "userId":"1001", "name":"william", "work":{ "company":{ "companyName":"tencent", "position":"java" }, "city":{ "area":"南山区", "street":"粤海街道" } } }
建筑设计事务所hcma视觉形象升级hcma成立于1976年,总部位于加拿大温哥华,在维多利亚和埃德蒙顿设有办事处,为众多客户设计各种项目,包括为机构客户设计学校公共安全建筑和健康中心为私营机构设计多功能住宅和其他商
高功率1。5T爆发300牛米,比凌渡还宽的家轿,静如图书馆,奕炫MAX国产自主品牌在SUV车型上的确颇有建树,比如哈弗H6长安CS75PLUS吉利博越奇瑞瑞虎8等常年都是稳居销量榜前列,让很多合资品牌都羡慕不已。然而拿得出手的轿车车型却又少之又少,主
脱口秀火了,王思聪也只配坐观众席?上周脱口秀大会第四季落幕,算上每期后面的加更,足足有28亿的播放量,傲视当前所有综艺节目。脱口秀江湖老手新兵重新划分势力版图之时,有眼尖的网友发现镜头扫过之处有个人貌似王思聪。镜头
美股又刷新高,A股奋起直追,美联储2018年会加息几次1月3日,周三美股有刷新高,三大股指齐齐的新高,标普500收涨0。64,首次收于2700点上方,道琼斯收涨0。40,纳斯达克收涨0。84。华尔街投行对2018年美股也是不约而同的看
为什么现在的人都不爱发朋友圈了呢?有的人一天可以发三到四次朋友圈,恨不得直播自己24小时的动态而有的人,基本上在朋友圈看不到他们的身影,两三个月看不到他们的动态,有时甚至大半年都没有动静,甚至从来不发朋友圈。那么不
史上最便宜的3360鼠标富勒G93Pro开箱测评这几日在网上闲逛,偶然得到消息之前测评过的富勒G93S推出了升级版G93Pro,进JD搜了一下,发现并无此产品销售,以为是空穴来风,然而马云家把我狠狠地打脸了一下。仔细一看简介,在
刷金币大涨的方法,亲测有效朋友们在刷赚金币软件时,是不是新人奖励多,几个月后金币越来越少,恢复出厂设置太麻烦?下面我教大家一个简单的方法,让你一直都是新用户!第一步打开手机设置。第二步找到手机分身,可能没个
贵手机,究竟值不值得买?这里有答案很多人在买手机之前,一般都会对手机进行一个大概的了解,比如处理器屏幕刷新率后置镜头参数等等,而在了解清楚后,你一开始买手机的要求几乎都会被改变,本来不在意的很多功能,现在你却全都想
瑞银首席经济学家报告公然使用Chinesepig,是歧视还是我们敏感瑞银(UBS)作为一家老牌的金融机构,首席经济学家paul却在报告中公然出现Chinesepig这样字眼,令人诧异之余更是震惊,使用如此不恰当言论,甚至略带歧视色彩,不仅在金融圈引
iQOONeo系列发展史iQOONeo系列是iQOO在2019年7月8日正式推出的一个系列,Neo系列自诞生以来的定位就是性能强,主要的消费群体多为学生党。1。iQOONeo845版本2。iQOONeo8
2610日报苹果发布iOS15。1正式版推出等特斯拉上海超级工厂数据中心建成昨天,特斯拉上海研发创新中心和特斯拉上海超级工厂数据中心均建设落成,并于近期投入使用。按照上海市数据中心建设导则(2021版)相关要求,特斯拉已经完成