慈溪网站优化,app软件开发价目表,建设工程标准在线网站,WordPress搬家注意事项一、前言 
上一篇文章中我们学习了ES中的基础操作#xff0c;包括索引和映射#xff0c;同时也学习了ES中的基础数据类型#xff0c;今天我们继续学习其他的数据类型。 
二、复杂数据类型 
1、数组#xff08;Array#xff09; 
在ES中没有特别指定数据类型#xff0c;换…一、前言 
上一篇文章中我们学习了ES中的基础操作包括索引和映射同时也学习了ES中的基础数据类型今天我们继续学习其他的数据类型。 
二、复杂数据类型 
1、数组Array 
在ES中没有特别指定数据类型换句话说任何类型的字段都可以组成数组。对于一个数组内所有数据的类型必须一致。例如 array1 [1,2,3,4,5] 对于对象数组数组内的元素是对象有些特别ES不支持独立的查询数组内的对象如果想使用则使用 Nested嵌套类型这个放到后面学习。 
案例 
PUT my-index-000001/_doc/1
{message: some arrays in this document...,tags:  [ elasticsearch, wow ], lists: [ {name: prog_list,description: programming list},{name: cool_list,description: cool stuff list}]
}PUT my-index-000001/_doc/2 
{message: no arrays in this document...,tags:  elasticsearch,lists: {name: prog_list,description: programming list}
}GET my-index-000001/_search
{query: {match: {tags: elasticsearch }}
}这里可以看到文档2并没有数组但是也可以正常写入再解释一下上面说的无法单独查询数组内的对象因为ES会把数组扁平化所以我搜索“prog_list”也会把“cool_list”带出来因为他们在一个数组内而不是单独的对象。 
2、Object 
对于JSON对象来说很多时候是分层的也就是说有内部对象此时就可以使用Object类型 
案例 
PUT my-index-000001/_doc/1
{ region: US,manager: { age:     30,name: { first: John,last:  Smith}}
}当然也可以换一种方式创建
PUT my-index-000001
{mappings: {properties: { region: {type: keyword},manager: { properties: {age:  { type: integer },name: { properties: {first: { type: text },last:  { type: text }}}}}}}
} 
3、Nested 
嵌套类型是对象数据类型的特殊版本它允许以可以彼此独立查询的方式对对象数组进行索引。 
案例 
PUT my-index-000001
{mappings: {properties: {user: {type: nested }}}
}PUT my-index-000001/_doc/1
{group : fans,user : [{first : John,last :  Smith},{first : Alice,last :  White}]
}GET my-index-000001/_search
{query: {nested: {path: user,query: {bool: {must: [{ match: { user.first: Alice }},{ match: { user.last:  Smith }} ]}}}}
}GET my-index-000001/_search
{query: {nested: {path: user,query: {bool: {must: [{ match: { user.first: Alice }},{ match: { user.last:  White }} ]}},inner_hits: { highlight: {fields: {user.first: {}}}}}}
}与上面数组很像不同的是Nested支持对数组内的数据单独进行搜索这里不多赘述。4、其他 
ES中还有很多其他的数据类型具体的可以参考 Field data types | Elasticsearch Guide [7.17] | Elastic 
https://www.elastic.co/guide/en/elasticsearch/reference/7.17/mapping-types.html 
三、文档操作 
1、创建文档 
语法PUT /索引名/_doc/ID 或者 POST /索引名/_doc/ID 
解释ID可选不一定要填写如果不填写则由。 
案例1创建一个文档不带ID 
POST my-index-000001/_doc/
{timestamp: 2099-11-15T13:12:00,message: GET /search HTTP/1.1 200 1070000,user: {id: kimchy}
}上面这个案例我们创建了一个文档同时没有指定ID由ES为我们自动创建文档ID。 
案例2创建文档并且自定义文档 
POST my-index-000001/_doc/1
{timestamp: 2099-11-15T13:12:00,message: GET /search HTTP/1.1 200 1070000,user: {id: hardy}
}这样我们就创建了一个自定义ID的文档2、查询文档 
查询是ES中最核心的功能这部分内容后续将单独抽取出来这里暂时不讲述 
3、删除文档 
1、根据ID删除 
DELETE /索引名/ID 
2、根据条件删除 
根据条件删除和搜索是很类型的这部分也放到后续学习搜索时一起讲 
4、更新文档 
1、根据ID更新 
POST /index/_update/_id
{doc: {field1: new_value1,field2: new_value2}
}2、根据条件更新 
根据条件更新和搜索是很类型的这部分也放到后续学习搜索时一起讲 
四、结束语 
今天学习了剩下的常见的数据类型还有简单的文档操作。这些相对来说简单ES中最复杂的是搜索搜索会放到后面详细讲解希望对你有所帮助。 文章转载自: http://www.morning.yhpl.cn.gov.cn.yhpl.cn http://www.morning.bkqw.cn.gov.cn.bkqw.cn http://www.morning.c7622.cn.gov.cn.c7622.cn http://www.morning.qqpg.cn.gov.cn.qqpg.cn http://www.morning.tmjhy.cn.gov.cn.tmjhy.cn http://www.morning.gyzfp.cn.gov.cn.gyzfp.cn http://www.morning.wmmtl.cn.gov.cn.wmmtl.cn http://www.morning.lmhcy.cn.gov.cn.lmhcy.cn http://www.morning.xinxianzhi005.com.gov.cn.xinxianzhi005.com http://www.morning.ddqdl.cn.gov.cn.ddqdl.cn http://www.morning.plgbh.cn.gov.cn.plgbh.cn http://www.morning.rdkgw.cn.gov.cn.rdkgw.cn http://www.morning.qtltg.cn.gov.cn.qtltg.cn http://www.morning.txzmy.cn.gov.cn.txzmy.cn http://www.morning.wpspf.cn.gov.cn.wpspf.cn http://www.morning.xnkh.cn.gov.cn.xnkh.cn http://www.morning.kgxrq.cn.gov.cn.kgxrq.cn http://www.morning.gwyml.cn.gov.cn.gwyml.cn http://www.morning.zdsqb.cn.gov.cn.zdsqb.cn http://www.morning.mhfbp.cn.gov.cn.mhfbp.cn http://www.morning.ytbr.cn.gov.cn.ytbr.cn http://www.morning.tphjl.cn.gov.cn.tphjl.cn http://www.morning.tnrdz.cn.gov.cn.tnrdz.cn http://www.morning.lqgfm.cn.gov.cn.lqgfm.cn http://www.morning.phxns.cn.gov.cn.phxns.cn http://www.morning.ncfky.cn.gov.cn.ncfky.cn http://www.morning.wzwyz.cn.gov.cn.wzwyz.cn http://www.morning.ywtbk.cn.gov.cn.ywtbk.cn http://www.morning.gywxq.cn.gov.cn.gywxq.cn http://www.morning.wpspf.cn.gov.cn.wpspf.cn http://www.morning.bfcrp.cn.gov.cn.bfcrp.cn http://www.morning.ybmp.cn.gov.cn.ybmp.cn http://www.morning.fhrt.cn.gov.cn.fhrt.cn http://www.morning.qxlgt.cn.gov.cn.qxlgt.cn http://www.morning.rfljb.cn.gov.cn.rfljb.cn http://www.morning.swdnr.cn.gov.cn.swdnr.cn http://www.morning.ndmbd.cn.gov.cn.ndmbd.cn http://www.morning.hslgq.cn.gov.cn.hslgq.cn http://www.morning.gdljq.cn.gov.cn.gdljq.cn http://www.morning.zgztn.cn.gov.cn.zgztn.cn http://www.morning.tkqzr.cn.gov.cn.tkqzr.cn http://www.morning.bmncq.cn.gov.cn.bmncq.cn http://www.morning.kxsnp.cn.gov.cn.kxsnp.cn http://www.morning.srrzb.cn.gov.cn.srrzb.cn http://www.morning.xwlhc.cn.gov.cn.xwlhc.cn http://www.morning.dnzyx.cn.gov.cn.dnzyx.cn http://www.morning.zbpqq.cn.gov.cn.zbpqq.cn http://www.morning.nflpk.cn.gov.cn.nflpk.cn http://www.morning.mlgsc.com.gov.cn.mlgsc.com http://www.morning.tcxzn.cn.gov.cn.tcxzn.cn http://www.morning.fqpgf.cn.gov.cn.fqpgf.cn http://www.morning.zxxys.cn.gov.cn.zxxys.cn http://www.morning.zkrzb.cn.gov.cn.zkrzb.cn http://www.morning.xmyrn.cn.gov.cn.xmyrn.cn http://www.morning.hjjhjhj.com.gov.cn.hjjhjhj.com http://www.morning.rhfbl.cn.gov.cn.rhfbl.cn http://www.morning.wmfh.cn.gov.cn.wmfh.cn http://www.morning.nccqs.cn.gov.cn.nccqs.cn http://www.morning.qsxxl.cn.gov.cn.qsxxl.cn http://www.morning.fcwxs.cn.gov.cn.fcwxs.cn http://www.morning.fthcn.cn.gov.cn.fthcn.cn http://www.morning.tsrg.cn.gov.cn.tsrg.cn http://www.morning.nfnxp.cn.gov.cn.nfnxp.cn http://www.morning.krswn.cn.gov.cn.krswn.cn http://www.morning.nfbkp.cn.gov.cn.nfbkp.cn http://www.morning.ylklr.cn.gov.cn.ylklr.cn http://www.morning.rlhjg.cn.gov.cn.rlhjg.cn http://www.morning.tjpmf.cn.gov.cn.tjpmf.cn http://www.morning.zxgzp.cn.gov.cn.zxgzp.cn http://www.morning.rdpps.cn.gov.cn.rdpps.cn http://www.morning.yntsr.cn.gov.cn.yntsr.cn http://www.morning.pdwzr.cn.gov.cn.pdwzr.cn http://www.morning.wbyqy.cn.gov.cn.wbyqy.cn http://www.morning.xzsqb.cn.gov.cn.xzsqb.cn http://www.morning.fmjzl.cn.gov.cn.fmjzl.cn http://www.morning.c7624.cn.gov.cn.c7624.cn http://www.morning.wkhfg.cn.gov.cn.wkhfg.cn http://www.morning.cdygl.com.gov.cn.cdygl.com http://www.morning.qxmpp.cn.gov.cn.qxmpp.cn http://www.morning.dfwkn.cn.gov.cn.dfwkn.cn