admin管理员组

文章数量:1123769

I have an elastic query as below:

{
    "query": {
        "bool": {
            "must": [
                {
                    "multi_match": {
                        "query": "my search term",
                        "fields": [
                            "title",
                            "keywords",
                            "text"
                        ]
                    }
                }
            ],
            "filter": [
                {
                    "terms": {
                        "catid": [
                            83
                        ]
                    }
                },
                {
                    "range": {
                        "updateDate": {
                            "gte": "now/d-30d",
                            "lte": "now/d"
                        }
                    }
                }
            ]
        }
    },
    "aggs": {
        "global_aggregation": {
            "global": {},
            "aggs": {
                "filtered_aggregation": {
                    "filter": {
                        "bool": {
                            "must": [
                                {
                                    "multi_match": {
                                        "query": "my search term",
                                        "fields": [
                                            "title",
                                            "keywords",
                                            "text"
                                        ]
                                    }
                                },
                                {
                                    "terms": {
                                        "status": [
                                            2
                                        ]
                                    }
                                }
                            ]
                        }
                    },
                    "aggs": {
                        "by_time_period": {
                            "date_histogram": {
                                "field": "updateDate",
                                "calendar_interval": "quarter",
                                "format": "yyyy-MM-dd",
                                "order": {
                                    "_key": "desc"
                                }
                            },
                            "aggs": {
                                "top_hits_per_bucket": {
                                    "top_hits": {
                                        "size": 10,
                                        "_source": [
                                            "title",
                                            "msid",
                                            "keywords",
                                            "updateDate"
                                        ]
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "size": 0,
    "_source": [
        "title",
        "msid",
        "keywords",
        "updateDate"
    ]
}

Now the problem is that in the aggregated results I am getting the date_histogram for results only for the last 30 days but the global aggregations should ignore the range query in the main search. What Can I do to fix this query? If I remove the range filter from main query I get the date histograms for all the past years since beginning

本文标签: