I indexed the post and community models,
post = Index('posts')
post.settings(
number_of_shards=1,
number_of_replicas=0
)
@post.doc_type
class PostDocument(DocType):
community = fields.ObjectField(properties={
'id': fields.IntegerField(),
'description': fields.TextField(),
'name': fields.StringField(),
})
I want to search posts and aggregate the communities
(returns communities of the posts in the result)
I may need to use aggregation, I had difficulties while implementing it, the documentation was not clear for me.
q = Q("multi_match", query=query, fields=['title', 'content'])
document.query(q)
document.aggs.bucket('per_tag', 'terms', field='community')
I think you need change the aggregation to something similar to:
document.aggs.bucket('per_tag', 'terms', field='community__id')
Because community is a complex objects, and elasticsearch only can do aggregation with simple fields. (keyword or integer)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.