"hits" : [
{
"_index" : "mytest",
"_type" : "doc,"
"_id" : "2",
"_score" : 1,
"_source" : {
"AuthorObjectJson" : [
{
"Name" : "wang wu,"
"Org" : "beihang university", "
},
{
"Name" : "zhao liu,"
"Org", "chongqing university", "
}
]
}
},
{
"_index" : "mytest",
"_type" : "doc,"
"_id" : "1",
"_score" : 1,
"_source" : {
"AuthorObjectJson" : [
{
"Name" : "zhang SAN",
"Org" : "beihang university", "
},
{
"Name" : "li si,"
"Org", "chongqing university", "
}
]
}
}
]
My index as the data on the AuthorObjectJson is a nested type, now I'd like to Org is beihang university are aggregated statistics, use the following query
GET mytest/_search
{
"Query" : {
"Bool" : {
"Must" : [
{
"Nested" : {
"Path" : "AuthorObjectJson,"
"Query" : {
"Match_phrase" : {
"AuthorObjectJson.Org", "beihang university", "
}
}
}
}
]
}
},
"Aggs" : {
"NAME" : {
"Nested" : {
"Path" : "AuthorObjectJson
"},
"Aggs" : {
"SDF" : {
"Terms" : {
"Field" : "AuthorObjectJson. Name. Keyword",
"Size" : 10
}
}
}
}
}
}
Get the following results:
"aggregations" : {
"NAME" : {
"Doc_count" : 4,
"SDF" : {
"Doc_count_error_upper_bound" : 0,
"Sum_other_doc_count" : 0,
"Buckets" : [
{
"Key" : "li si,"
1
"doc_count" :},
{
"Key" : "wang wu,"
1
"doc_count" :},
{
"Key" : "zhang SAN",
1
"doc_count" :},
{
"Key" : "zhao liu,"
1
"doc_count" :}
]
}
}
}
This is not what I want results, what I want is zhang SAN and wangwu two of them is beihang university students, this how to solve?