赞
踩
put scrm_staff_rel_index
{
"mappings":{
"properties":{
"staff_office_relation":{
"type":"join",
"relations":{
"scrm_staff":"scrm_staff_office_rel"
}
}
}
}
}
post scrm_staff_rel_index/_doc/staff1 { "staff_id":1, "staff_name":"windDrift", "staff_office_relation":{ "name":"scrm_staff" } } post scrm_staff_rel_index/_doc/staff2 { "staff_id":2, "staff_name":"tangya", "staff_office_relation":{ "name":"scrm_staff" } }
put scrm_staff_rel_index/_doc/office_rel1?routing=staff1 { "office_name":"湖南", "office_code":"hunan", "staff_office_relation":{ "name":"scrm_staff_office_rel", "parent":"staff1" } } put scrm_staff_rel_index/_doc/office_rel2?routing=staff2 { "office_name":"衡阳金甲领", "office_code":"hyjjl", "staff_office_relation":{ "name":"scrm_staff_office_rel", "parent":"staff2" } }
GET scrm_staff_rel_index/_doc/staff1
GET scrm_staff_rel_index/_doc/office_rel1?routing=staff1
GET scrm_staff_rel_index/_search
{
"query": {
"has_child": {
"type": "scrm_staff_office_rel",
"query": {
"match": {
"office_code": "hunan"
}
}
}
}
}
GET scrm_staff_rel_index/_search
{
"query": {
"has_parent": {
"parent_type": "scrm_staff",
"query": {
"match": {
"staff_name": "windDrift"}}}}}
PUT scrm_staff { "mappings":{ "properties":{ "scrm_office":{ "type":"nested", "properties":{ "office_name":{"type":"keyword"}, "office_code":{"type":"keyword"} } }, "name":{"type":"text","fields": {"keyword":{"type":"keyword","ignore_above":256}}} } } }
POST scrm_staff/_doc/1
{
"name":"windDrift",
"scrm_office":[
{
"office_name":"湖南",
"office_code":"hunan"
},{
"office_name":"深圳",
"office_code":"shenzhen"
}
]
}
Nested嵌套文档查询
POST scrm_staff/_search { "query":{ "bool": { "must": [ {"match": { "name": "windDrift"}}, { "nested": { "path": "scrm_office", "query": { "bool": { "must": [ { "match": {"scrm_office.office_code": "hunan" }}, { "match": {"scrm_office.office_name": "湖南" }} ] } } } } ]
Nested嵌套文档聚合分析
POST scrm_staff/_search { "aggs":{ "nameAggs":{ "nested": { "path": "scrm_office" }, "aggs": { "nameAggs": { "terms": { "field": "scrm_office.office_code", "size": 10 } } } } } }
普通的agg是不生效的
POST scrm_staff/_search
{
"aggs": {
"nameAgg": {
"terms": {"field": "scrm_office.office_name"}
}
}
}
普通agg查询这里的聚合没有生效
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。