# In the process of query using date sorting, why so time-consuming?

**URL:** https://discuss.elastic.co/t/in-the-process-of-query-using-date-sorting-why-so-time-consuming/98951
**Category:** Elasticsearch
**Created:** [August 31, 2017, 7:07am UTC](https://discuss.elastic.co/t/in-the-process-of-query-using-date-sorting-why-so-time-consuming/98951 "2017-08-31T07:07:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![qin](https://avatars.discourse-cdn.com/v4/letter/q/91b2a8/32.png) [@qin](https://discuss.elastic.co/u/qin)
#### Post date: [August 31, 2017, 7:07am UTC](https://discuss.elastic.co/t/in-the-process-of-query-using-date-sorting-why-so-time-consuming/98951/1 "2017-08-31T07:07:04Z")

</div>

**elasticsearch version:** 5.0

```auto
Use date sort:
GET /logstash-spider-user-*/525983/_search 
{
  "from":0,
  "size":10,
  "query": {
    "bool": {
      "must": [
        {
        "match": {
          "level": "INFO"
        }
        }
      ],
      "filter": [
        {
          "range": {
           "@timestamp": {
              "gte": "2017-08-30 10:00:00",
              "lte": "now",
              "format": "yyyy-MM-dd HH:mm:ss",
              "time_zone": "+08:00"
            }
          }
        }
      ]
    }
  },
  "sort": [
    {
      "@timestamp": {
        "order": "desc"
      }
    }
  ],
 "highlight":{ 
    "pre_tags" : ["<tag>"],
    "post_tags" : ["</tag>"],
    "fields":{
    "message":{}
    }
   }
}

```

result:

```auto
{
  "took": 36685,
  "timed_out": false,
  "_shards": {
    "total": 4,
    "successful": 4,
    "failed": 0
  },
  "hits": {
    "total": 26153559,
    "max_score": null,

```

  

```auto
Use default sort:
GET /logstash-spider-user-*/525983/_search 
{
  "from":0,
  "size":10,
  "query": {
    "bool": {
      "must": [
      ],
      "filter": [
        {
          "range": {
           "@timestamp": {
              "gte": "2017-08-30 10:00:00",
              "lte": "now",
              "format": "yyyy-MM-dd HH:mm:ss",
              "time_zone": "+08:00"
            }
          }
        }
      ]
    }
  },

 "highlight":{ 
    "pre_tags" : ["<tag>"],
    "post_tags" : ["</tag>"],
    "fields":{
    "message":{}
    }
   }
}

```

result:

```auto
{
  "took": 4459,
  "timed_out": false,
  "_shards": {
    "total": 4,
    "successful": 4,
    "failed": 0
  },
  "hits": {
    "total": 26153559,
    "max_score": 0,

```

Why the difference so big ?

---

<div class="post-metadata">

### Author: ![qin](https://avatars.discourse-cdn.com/v4/letter/q/91b2a8/32.png) [@qin](https://discuss.elastic.co/u/qin)
#### Post date: [August 31, 2017, 7:09am UTC](https://discuss.elastic.co/t/in-the-process-of-query-using-date-sorting-why-so-time-consuming/98951/2 "2017-08-31T07:09:38Z")

</div>

**date sort:**  
cost time : 30+s  
**default sort:**  
cost time: 4+s

---

<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: [September 28, 2017, 7:09am UTC](https://discuss.elastic.co/t/in-the-process-of-query-using-date-sorting-why-so-time-consuming/98951/3 "2017-09-28T07:09:52Z")

</div>

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