1.nested Object mapping及查詢
//mapping中原來(lái)是object的地方替代之径簿,就是 nested object了
//nested對(duì)象將不被平整化(flatted object fileds)祠肥,object中的各字段仍保持關(guān)聯(lián)
//平整化會(huì)將object中的字段解析成object_name.object_filed_name的形式
PUT [index_name]
{
"mappings":{
"blogpost":{
"properties":{
"comments":{
"type":"nested",
"include_in_parent":true,
"properties":{
"name": {"type":"string" },
"comment": { "type": "string" },
"age": { "type": "short" },
"stars": { "type": "short" },
"date": { "type": "date" }
}
}
}
}
}
}
//nested查詢
GET [index_name]/[type_name]/_search
{
"query":{
"bool":{
"must":[
{"match":{"title":"eggs"}},
{
"nested":{
"path":"comments",
"query":{
"bool":{
"must":[
{"match":{"comments.name":"john"}},
{"match":{"comments.age":28}}
]
}
}
}
}
]
}
}
}
進(jìn)階:Elasticsearch之Nested(嵌套)系列橡淑、es權(quán)威指南-嵌套-查詢怒医、es權(quán)威指南-嵌套-對(duì)象(官方文檔中文詳細(xì)解釋)
2.父子文檔
//建立文檔的父子關(guān)系要在創(chuàng)建索引的時(shí)候在mapping中聲明哪個(gè)是父文檔哪個(gè)是子文檔岭埠。
/創(chuàng)建了一個(gè)索引,并制定了2個(gè)type和它們之間的父子關(guān)系音榜。
PUT [index_name]
{
"mappings": {
"branch": {},
"employee": {
"_parent": {
"type": "branch"
}
}
}
}
//索引子文檔要注明爸爸是誰(shuí)必搞,父文檔不用標(biāo)注兒子是誰(shuí)
//子文檔的每條文檔設(shè)置parent屬性的value為父文檔id
PUT [index_name]/company/employee/1?parent=london&pretty
{
"name": "Alice Smith",
"dob": "1970-10-24",
"hobby": "hiking"
}
//通過(guò)子文檔查父文檔
//搜索含有1980年以后出生的employee的branch
GET [index_name]/branch/_search
{
"query": {
"has_child": {
"type": "employee",
"query": {
"range": {
"dob": {
"gte": "1980-01-01"
}
}
}
}
}
}
//搜索最少有兩個(gè)employee的branch
GET [index_name]/branch/_search
{
"query": {
"has_child": {
"type":"employee",
"min_children": 2,
"query": {
"match_all": {}
}
}
}
}
//通過(guò)父文檔查子文檔
GET [index_name]/employee/_search
{
"query": {
"has_parent": {
"type": "branch",
"query": {
"match": {
"country": "UK"
}
}
}
}
進(jìn)階:Elasticsearch索引的父子關(guān)系(index parent-child)、Elasticsearch Java API(七)--多級(jí)嵌套搜索(3級(jí))
3.查看熱點(diǎn)線程
//查看cpu占用高且執(zhí)行時(shí)間長(zhǎng)的Java線程
GET _nodes/_nodes/hot_threads
4.查看集群統(tǒng)計(jì)信息
GET _stats
GET _stats?pretty'
5. 禁用all字段
PUT my_index
{
"mappings": {
"type_1": {
"properties": {...}
},
"type_2": {
"_all": {
"enabled": false//禁用
},
"properties": {...}
}
}
}
6. 刪除文檔
//刪除type下所有
DELETE /mytest/test/_query
{
"query": {
"match_all": {}
}
}
//刪除指定id文檔
DELETE /website/blog/1234
7. 新建mapping
PUT mcms_iflow/_mapping/tbl_iflow_feature
{
"_all": {
"enabled": false
},
"properties": {
"id": {
"type": "string"
},
"tags": {
"type": "string"
},
"title": {
"type": "string"
},
"add_time": {
"type": "long"
}
}
}
8. 新建文檔數(shù)據(jù)
ElasticSearch如何添加囊咏,檢索數(shù)據(jù)
//新增和更新
PUT mcms_iflow/tbl_iflow_feature/11
{
"id": "1",
"tags": "woshi,我是,biaoiqan",
"title": "title標(biāo)題",
"add_time": "1500000000000"
}
//新增文檔,默認(rèn)自增id
POST mcms_iflow/tbl_iflow_feature
{
"id": "1",
"tags": "woshi,我是,biaoiqan",
"title": "title標(biāo)題",
"add_time": "1500000000000"
}