# Sorting by two fields (Date & Time)

**URL:** <https://discuss.elastic.co/t/sorting-by-two-fields-date-time/1477>\
**Category:** Elasticsearch\
**Created:** [May 28, 2015, 2:32pm UTC](https://discuss.elastic.co/t/sorting-by-two-fields-date-time/1477 "2015-05-28T14:32:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pennywise83](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pennywise83/32/432_2.png) [@Pennywise83](https://discuss.elastic.co/u/Pennywise83)\
**Post date:** [May 28, 2015, 2:32pm UTC](https://discuss.elastic.co/t/sorting-by-two-fields-date-time/1477/1 "2015-05-28T14:32:03Z")

</div>

Hi,  
I have an index with the following mapping:

```
{
    "mappings": {
        "testtype": {
            "properties": {
                "DATE": {
                    "format": "yyyy-MM-dd-HH.mm.ss",
                    "type": "date"
                },
                "TIME": {
                    "format": "HHmmss",
                    "type": "date"
                }
            }
        }
    }
}

```

I need to do a query\_string ordered by DATE and TIME combined, so I've tried to make the request with the following query:

```
{
    "from": 0,
    "size": 50,
    "query": {
        "bool": {
            "must": [
                {
                    "query_string": {
                        "query": "testField:testValue"
                    }
                }
            ]
        }
    },
    "sort": [
        {
            "DATE": {
                "order": "desc"
            }
        },
        {
            "TIME": {
                "order": "desc"
            }
        }
    ]
}

```

Unfortunately that doesn't seems to work, for example if i use pagination (i.e.: FROM=2) I get only the current result ordered. How can I sort the entire result?

---

<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:** [July 6, 2017, 12:11am UTC](https://discuss.elastic.co/t/sorting-by-two-fields-date-time/1477/2 "2017-07-06T00:11:16Z")

</div>


