# A slow query problem in elasticsearch (aggregation)

**URL:** https://discuss.elastic.co/t/a-slow-query-problem-in-elasticsearch-aggregation/344793
**Category:** Elasticsearch
**Created:** [October 11, 2023, 7:59am UTC](https://discuss.elastic.co/t/a-slow-query-problem-in-elasticsearch-aggregation/344793 "2023-10-11T07:59:48Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![haipeng.zhao](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/haipeng.zhao/32/84582_2.png) [@haipeng.zhao](https://discuss.elastic.co/u/haipeng.zhao)
#### Post date: [October 11, 2023, 7:59am UTC](https://discuss.elastic.co/t/a-slow-query-problem-in-elasticsearch-aggregation/344793/1 "2023-10-11T07:59:48Z")

</div>

Please help me optimize this query. The index is 800mb and the query time is about to exceed 1 second.

```json
{
    "from": 0,
    "size": 300,
    "explain": "true",
    "_source": [
        "sku_id",
        "upc",
        "spu_id",
        "title",
        "primary_desc",
        "brand",
        "upc_desc",
        "dept_desc",
        "category_desc",
        "fineline_desc",
        "effective_date",
        "dept_nbr",
        "category_nbr",
        "fineline_nbr",
        "category_stream",
        "manual_words",
        "forbidden_words",
        "sales_num",
        "category_front_id",
        "brand_name",
        "item_type",
        "brand_id",
        "category_front_name"
    ],
    "query": {
        "bool": {
            "must": [
                {
                    "multi_match": {
                        "query": "milk",
                        "fields": [
                            "title^10",
                            "primary_desc^10",
                            "brand^10",
                            "manual_words^50",
                            "upc_desc^5",
                            "short_text^5",
                            "selling_points",
                            "dept_desc^5",
                            "category_desc^5",
                            "fineline_desc^5",
                            "category_back_name^5",
                            "category_front_name^5",
                            "brand_name^10",
                            "click_stream^3",
                            "click_stream.break_both^3",
                            "session_stream",
                            "session_stream.break_both",
                            "category_stream^20",
                            "category_query_stream"
                        ],
                        "type": "cross_fields",
                        "minimum_should_match": "60%" }
                },
                {
                    "term": {
                        "data_type": 2
                    }
                },
                {
                    "has_child": {
                        "type": "store",
                        "query": {
                            "bool": {
                                "must": [
                                    {
                                        "terms": {
                                            "store_id": [
                                                "1059",
                                                "9635",
                                                "5148"
                                            ]
                                        }
                                    },
                                    {
                                        "term": {
                                            "is_valid": 1
                                        }
                                    },
                                    {
                                        "term": {
                                            "data_type": 2
                                        }
                                    }
                                ]
                            }
                        },
                        "inner_hits": {
                            "_source": [
                                "store_id",
                                "price",
                                "delivery_attr",
                                "reseller"
                            ]
                        }
                    }
                }
            ]
        }
    }
}

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [November 8, 2023, 8:00am UTC](https://discuss.elastic.co/t/a-slow-query-problem-in-elasticsearch-aggregation/344793/2 "2023-11-08T08:00:32Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
