# Elasticsearch Query DSL help need to sort on timestamp

**URL:** <https://discuss.elastic.co/t/elasticsearch-query-dsl-help-need-to-sort-on-timestamp/278634>\
**Category:** Kibana\
**Created:** [July 14, 2021, 9:41am UTC](https://discuss.elastic.co/t/elasticsearch-query-dsl-help-need-to-sort-on-timestamp/278634 "2021-07-14T09:41:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bab](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bab/32/86201_2.png) [@bab](https://discuss.elastic.co/u/bab)\
**Post date:** [July 14, 2021, 9:41am UTC](https://discuss.elastic.co/t/elasticsearch-query-dsl-help-need-to-sort-on-timestamp/278634/1 "2021-07-14T09:41:02Z")

</div>

i need your Help Expertes, i need to update this query to be able to get the result filtered on **Prim\_id** alphabetic and **timestamp** ascending, each Prim\_id is present in a log-event sorted on timestamp (log time).  
i mean , for example prim\_id : Ca11 is present in many times whit different content (message), i want to be able to get all log-event with Ca11 listed based on log timestamp (log time), after that the same for Ca12,Ca25...etc

```auto
{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "message": "Ca12"
          }
        },
        {
          "match_phrase": {
            "message": "Ca25"
          }
        },
        {
          "match_phrase": {
            "message": "Ca11"
          }
        },
       {
          "match_phrase": {
            "message": "Ca98"
          }
        }
      ],
      "minimum_should_match": 1
    }
  }
}

```

thank you guys in advance.

---

<div class="post-metadata">

**Author:** ![cheiligers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cheiligers/32/73114_2.png) [@cheiligers](https://discuss.elastic.co/u/cheiligers)\
**Post date:** [July 14, 2021, 7:02pm UTC](https://discuss.elastic.co/t/elasticsearch-query-dsl-help-need-to-sort-on-timestamp/278634/2 "2021-07-14T19:02:07Z")

</div>

@bab You could try using a [multi-term aggregation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-multi-terms-aggregation.html)

---

<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:** [August 11, 2021, 7:02pm UTC](https://discuss.elastic.co/t/elasticsearch-query-dsl-help-need-to-sort-on-timestamp/278634/3 "2021-08-11T19:02:51Z")

</div>

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