# Sort on multiple fields not working

**URL:** <https://discuss.elastic.co/t/sort-on-multiple-fields-not-working/289478>\
**Category:** Elasticsearch\
**Created:** [November 17, 2021, 3:56pm UTC](https://discuss.elastic.co/t/sort-on-multiple-fields-not-working/289478 "2021-11-17T15:56:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karthikeyan\_Amaresan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karthikeyan_amaresan/32/94017_2.png) [@Karthikeyan\_Amaresan](https://discuss.elastic.co/u/Karthikeyan_Amaresan)\
**Post date:** [November 17, 2021, 3:56pm UTC](https://discuss.elastic.co/t/sort-on-multiple-fields-not-working/289478/1 "2021-11-17T15:56:22Z")

</div>

**Query**

```auto
{
  "size": 20,
  "query": {
    "match_all": {} 
  },
  "_source": ["INBOUND_CALL_mod_date", "OUTBOUND_CALL_mod_date"],
  "sort": [
    {
      "INBOUND_CALL_mod_date": {
        "order": "desc"
      }
    },
    {
      "OUTBOUND_CALL_mod_date": {
        "order": "desc"
      }
    }
  ],
  "track_total_hits": true
}

```

**Response JSON**

```auto
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 20,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [
      {
        "_index" : "multi-sort-test-index",
        "_type" : "_doc",
        "_id" : "17",
        "_score" : null,
        "_source" : {
          "INBOUND_CALL_mod_date" : "2021-11-09T11:44:23.823+0000"
        },
        "sort" : [
          1636458263823,
          -9223372036854775808
        ]
      },
      {
        "_index" : "multi-sort-test-index",
        "_type" : "_doc",
        "_id" : "18",
        "_score" : null,
        "_source" : {
          "INBOUND_CALL_mod_date" : "2021-11-02T13:44:13.654+0000"
        },
        "sort" : [
          1635860653654,
          -9223372036854775808
        ]
      },
      {
        "_index" : "multi-sort-test-index",
        "_type" : "_doc",
        "_id" : "19",
        "_score" : null,
        "_source" : {
          "INBOUND_CALL_mod_date" : "2021-10-29T13:22:27.917+0000"
        },
        "sort" : [
          1635513747917,
          -9223372036854775808
        ]
      },
      {
        "_index" : "multi-sort-test-index",
        "_type" : "_doc",
        "_id" : "20",
        "_score" : null,
        "_source" : {
          "INBOUND_CALL_mod_date" : "2021-10-29T13:17:56.599+0000"
        },
        "sort" : [
          1635513476599,
          -9223372036854775808
        ]
      },
      {
        "_index" : "multi-sort-test-index",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : null,
        "_source" : {
          "OUTBOUND_CALL_mod_date" : "2021-11-09T12:57:34.752+0000"
        },
        "sort" : [
          -9223372036854775808,
          1636462654752
        ]
      },
      {
        "_index" : "multi-sort-test-index",
        "_type" : "_doc",
        "_id" : "3",
        "_score" : null,
        "_source" : {
          "OUTBOUND_CALL_mod_date" : "2021-11-09T12:51:38.292+0000"
        },
        "sort" : [
          -9223372036854775808,
          1636462298292
        ]
      }
    ]
  }
}

```

As per the response below is the sorted list by two date fields with recent most date.

 ![Screenshot 2021-11-17 at 9.19.04 PM](https://us1.discourse-cdn.com/elastic/original/3X/5/3/53a9825609fc457f2e291f203cc77c2c2194c1fe.png)

But shouldn't the **nov 09** documents highlighted in 5 and 6 position appear on 1 and 2 position respectively?

Thanks in advance.

---

<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:** [December 15, 2021, 3:56pm UTC](https://discuss.elastic.co/t/sort-on-multiple-fields-not-working/289478/2 "2021-12-15T15:56:58Z")

</div>

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