Я работаю над проектом, используя Elasticsearch с Spring Data Elasticsearch 5.2.6, и у меня возникают трудности для правильной реализации вложенных агрегатов. Буду очень признателен за любую помощь или рекомендации.
Сопоставление индексов
Вот соответствующая часть моего сопоставления индексов:
Код: Выделить всё
{
"actions" : {
"mappings" : {
"properties" : {
"actionRoles" : {
"type" : "nested",
"properties" : {
"roleName" : {
"type" : "keyword"
}
}
},
// ... other fields ...
}
}
}
}
Код: Выделить всё
fun toNativeQuery(): NativeQuery {
val criteriaQuery = CriteriaQuery(criteria)
val queryBuilder = NativeQuery.builder().withQuery(criteriaQuery)
//...
queryBuilder.withAggregation(
AGG_ACTION_ROLE,
//TODO: Add the nested aggregation for 'actionRoles.roleName'
)
//...
return queryBuilder.build()
}
Код: Выделить всё
{
"aggregations": {
"actionRoles": {
"nested": {
"path": "actionRoles"
},
"aggregations": {
"roleNames": {
"terms": {
"field": "actionRoles.roleName",
"size": 1000
}
}
}
}
}
Думаю, мне придется это сделать сделайте что-нибудь вроде
Код: Выделить всё
queryBuilder.withAggregation(
AGG_ACTION_ROLE,
//TODO: Add the nested aggregation for 'actionRoles'
AggregationBuilders.nested {
//how to do the nested aggregation here?
}
)
Подробнее здесь: https://stackoverflow.com/questions/786 ... search-5-2