如何加快ElasticSearch聚合过滤器查询?

时间:2019-12-19 10:02:05

标签: elasticsearch elasticsearch-aggregation

我有以下查询:

    "size": 0,
"aggs": {
    "count_group": {
        "filters": {
            "filters": {
                "75407042": {
                    "term": {
                        "supplier.id": 75407042
                    }
                },
                "89630201": {
                    "term": {
                        "supplier.id": 89630201
                    }
                }
            }
        },
        "aggs": {
            "market": {
                "terms": {
                    "field": "supplier_nom.id",
                    "size": 100000
                }
            }
        }
    }
},
"query": {
    "bool": {
        "must": [
            {
                "has_parent": {
                    "parent_type": "doc",
                    "query": {
                        "bool": {
                            "must": [
                                {
                                    "range": {
                                        "created": {
                                            "lte": "now/d"
                                        }
                                    }
                                },
                                {
                                    "range": {
                                        "expires": {
                                            "gte": "now/d"
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            },
            {
                "term": {
                    "doc_type": "item"
                }
            }
        ]
    }
}

}

查询的想法是根据供应商ID字段(整数字段)中的某些ID汇总过滤器中的文档。我得到了一些结果。

{
"took": 69,
"timed_out": false,
"_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
},
"hits": {
    "total": 275977,
    "max_score": 0.0,
    "hits": []
},
"aggregations": {
    "count_group": {
        "buckets": {
            "75407042": {
                "doc_count": 2,
                "market": {
                    "doc_count_error_upper_bound": 0,
                    "sum_other_doc_count": 0,
                    "buckets": [
                        {
                            "key": 108099149,
                            "doc_count": 1
                        },
                        {
                            "key": 108104828,
                            "doc_count": 1
                        }
                    ]
                }
            }

query

但是随后我在过滤器字段中放置了更多的ID,查询开始工作得慢得多。有什么方法可以加快查询速度(可能将其重写吗?),但保持查询逻辑不变。

0 个答案:

没有答案