简体   繁体   English

弹性搜索聚合[python]

[英]elastic-Search Aggregation [python]

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. 因为社区是一个复杂的对象,所以elasticsearch只能对简单字段进行聚合。 (keyword or integer) (关键字或整数)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM