API version: 0.3.0

---

# Reverse sorting

This example is the [sorting example](/reference/search/elasticsearch-query-dsl-mixin/sorting.md) in descending order: the
full text search for "lily" is sorted by the name of the plants, but with `"order": "desc"`, so the results start with
the last name in alphabetical order. The search is restricted to plants, and only the first three results are returned.

```bash
curl -X POST \
  -H 'Authorization: Bearer secret-token:PIPeJGUt7c00ENn8a5uDlc' \
  -H 'Content-Type: application/json' \
  -d '{
        "debug": true,
        "steps": [
          {
            "type": "elasticsearch-query-dsl-mixin",
            "query": {
              "query": {
                "match": {
                  "description": "lily"
                }
              },
              "sort": [
                {
                  "name.keyword": "desc"
                }
              ]
            },
            "parameters": {
              "nodeTypes": [
                "Plant"
              ],
              "pageSize": 3
            }
          },
          {
            "type": "element-hydration"
          }
        ]
      }' \
  https://api.example.com/search
```

##### Response Body

```json
{
  "type": "_SearchResultResponse",
  "results": [
    {
      "type": "Plant",
      "id": "02IiNr0GOoKiPMMBnI2aIF8Qd4GH33FIAozo7",
      "data": {
        "images": [
          {
            "description": "in Seoul Forest, South Korea",
            "imageLinkFull": "https://upload.wikimedia.org/wikipedia/commons/7/7b/Tulips_in_Seoul_Forest%2C_South_Korea1.jpg",
            "imageLinkThumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/7/7b/Tulips_in_Seoul_Forest%2C_South_Korea1.jpg...",
            "link": "https://en.wikipedia.org/wiki/File:Tulips_in_Seoul_Forest,_South_Korea1.jpg"
          },
          {
            "description": "A Yonina cultivar (Division 6) tulip at the Tulip Fest in Albany, New York, United States.",
            "imageLinkFull": "https://upload.wikimedia.org/wikipedia/commons/7/7b/Yonina_Tulip.jpg",
            "imageLinkThumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/7/7b/Yonina_Tulip.jpg/960px-Yonina_Tulip.jpg",
            "link": "https://en.wikipedia.org/wiki/File:Yonina_Tulip.jpg"
          },
          {
            "description": "Tulipa orphanidea, garden plant",
            "imageLinkFull": "https://upload.wikimedia.org/wikipedia/commons/c/c4/Tulipa_orphanidea_060506.jpg",
            "imageLinkThumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c4/Tulipa_orphanidea_060506.jpg/500px-Tulipa_...",
            "link": "https://en.wikipedia.org/wiki/File:Tulipa_orphanidea_060506.jpg"
          }
        ],
        "hasFile": true,
        "name": "Tulip",
        "scenario": "general.botanicExample",
        "scientificName": "Tulipa",
        "link": "https://en.wikipedia.org/wiki/Tulip",
        "description": "Tulips are spring-blooming perennial herbaceous bulbiferous geophytes in the Tulipa genus. Their flo...",
        "createdAt": "2026-12-05T12:21:40+00:00",
        "updatedAt": "2026-12-05T12:21:40+00:00"
      },
      "file": {
        "contentLength": 105488,
        "extension": "jpg",
        "mimeType": "image/jpeg",
        "hash": {
          "sha256": "c4c242897c43a74e9e4a8b5bf89e6b2cb1cbd99f8d621f33eea175cbf6dfab97"
        }
      },
      "metadata": {
        "score": 1.9555748,
        "sort": [
          "Tulip"
        ]
      }
    },
    {
      "type": "Plant",
      "id": "02IiNr0GOoKiPMN3kwX8zU4CDN8SlR7WlvzLO",
      "data": {
        "images": [
          {
            "description": "Red-hot poker plants (Kniphofia uvaria) on the shore of Lake Jindabyne, New South Wales, Australia.",
            "imageLinkFull": "https://upload.wikimedia.org/wikipedia/commons/c/c1/Kniphofia_uvaria_close.JPG",
            "imageLinkThumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Kniphofia_uvaria_close.JPG/960px-Kniphofia...",
            "link": "https://en.wikipedia.org/wiki/File:Kniphofia_uvaria_close.JPG"
          }
        ],
        "hasFile": true,
        "name": "Red Hot Poker",
        "scenario": "general.botanicExample",
        "scientificName": "K. uvaria",
        "link": "https://en.wikipedia.org/wiki/Kniphofia_uvaria",
        "description": "Kniphofia uvaria is a species of flowering plant in the family Asphodelaceae, commonly known as trit...",
        "createdAt": "2026-12-05T12:21:40+00:00",
        "updatedAt": "2026-12-05T12:21:40+00:00"
      },
      "file": {
        "contentLength": 123686,
        "extension": "jpg",
        "mimeType": "image/jpeg",
        "hash": {
          "sha256": "a0f461e0383bc5b4518a43e1ac76060612c7e87bf420f9a6bbbe5231012108fe"
        }
      },
      "metadata": {
        "score": 3.2452915,
        "sort": [
          "Red Hot Poker"
        ]
      }
    },
    {
      "type": "Plant",
      "id": "02IiNr0GOoKiPMM1RjHnrdKCZC9YSQcRh6HVB",
      "data": {
        "images": [
          {
            "description": "Saucer Magnolia -- Magnolia × soulangeana 'Rustica Rubra' found in Houston, Texas",
            "imageLinkFull": "https://upload.wikimedia.org/wikipedia/commons/6/6f/Saucer_Magnolia_--_Magnolia_%C3%97_soulangeana.j...",
            "imageLinkThumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Saucer_Magnolia_--_Magnolia_%C3%97_soulang...",
            "link": "https://en.wikipedia.org/wiki/File:Saucer_Magnolia_--_Magnolia_%C3%97_soulangeana.jpg"
          },
          {
            "description": "Yulan Magnolia (Magnolia denudata)",
            "imageLinkFull": "https://upload.wikimedia.org/wikipedia/commons/6/62/Yulan_1.JPG",
            "imageLinkThumbnail": "https://upload.wikimedia.org/wikipedia/commons/6/62/Yulan_1.JPG",
            "link": "https://en.wikipedia.org/wiki/File:Yulan_1.JPG"
          }
        ],
        "hasFile": true,
        "name": "Magnolia",
        "scenario": "general.botanicExample",
        "scientificName": "M. denudata",
        "link": "https://en.wikipedia.org/wiki/Magnolia_denudata",
        "description": "Magnolia denudata, the lilytree or Yulan magnolia (simplified Chinese: \\u7389\\u5170\\u82b1; tradition...",
        "createdAt": "2026-12-05T12:21:40+00:00",
        "updatedAt": "2026-12-05T12:21:40+00:00"
      },
      "file": {
        "contentLength": 50389,
        "extension": "jpg",
        "mimeType": "image/jpeg",
        "hash": {
          "sha256": "c615404e051e1e2e6c1d107cb7c043fd0db9a71eb9671be35533e9aac5e72e82"
        }
      },
      "metadata": {
        "score": 2.0758078,
        "sort": [
          "Magnolia"
        ]
      }
    }
  ],
  "debug": [
    {
      "input": {
        "type": "elasticsearch-query-dsl-mixin",
        "query": {
          "query": {
            "match": {
              "description": "lily"
            }
          },
          "sort": [
            {
              "name.keyword": "desc"
            }
          ]
        },
        "parameters": {
          "nodeTypes": [
            "Plant"
          ],
          "pageSize": 3,
          "stepResults": []
        }
      },
      "step-handler": "elasticsearch-query-dsl-mixin (App\\EventSystem\\SearchStep\\EventListener\\ElasticsearchQueryDslMixinSe...",
      "start": 1796473377.145045,
      "indices": "node_plant",
      "combinedQuery": {
        "_source": [
          "_id"
        ],
        "from": 0,
        "size": 3,
        "query": {
          "bool": {
            "must": [
              {
                "match": {
                  "description": "lily"
                }
              }
            ],
            "filter": [
              {
                "bool": {
                  "should": [
                    {
                      "terms": {
                        "_groupsWithSearchAccess.keyword": []
                      }
                    },
                    {
                      "term": {
                        "_usersWithSearchAccess.keyword": {
                          "value": "02IiNr0GOoKiPMM5A0eq9jHk2upaJezsVtWjL"
                        }
                      }
                    }
                  ],
                  "minimum_should_match": 1
                }
              }
            ]
          }
        },
        "sort": [
          {
            "name.keyword": "desc"
          }
        ],
        "track_scores": true
      },
      "end": 1796473377.155889,
      "duration": 0.010844
    },
    {
      "input": {
        "type": "element-hydration",
        "query": null,
        "parameters": {
          "stepResults": [
            {
              "elements": [
                {
                  "id": "02IiNr0GOoKiPMMBnI2aIF8Qd4GH33FIAozo7",
                  "type": "Plant",
                  "metadata": {
                    "score": 1.9555748,
                    "sort": [
                      "Tulip"
                    ]
                  }
                },
                {
                  "id": "02IiNr0GOoKiPMN3kwX8zU4CDN8SlR7WlvzLO",
                  "type": "Plant",
                  "metadata": {
                    "score": 3.2452915,
                    "sort": [
                      "Red Hot Poker"
                    ]
                  }
                },
                {
                  "id": "02IiNr0GOoKiPMM1RjHnrdKCZC9YSQcRh6HVB",
                  "type": "Plant",
                  "metadata": {
                    "score": 2.0758078,
                    "sort": [
                      "Magnolia"
                    ]
                  }
                }
              ],
              "totalHits": 8,
              "maxScore": 4.001134
            }
          ]
        }
      },
      "step-handler": "element-hydration (App\\EventSystem\\SearchStep\\EventListener\\ElementHydrationSearchStepEventListener)",
      "start": 1796473377.1564,
      "accessibleElementIds": [
        "02IiNr0GOoKiPMMBnI2aIF8Qd4GH33FIAozo7",
        "02IiNr0GOoKiPMN3kwX8zU4CDN8SlR7WlvzLO",
        "02IiNr0GOoKiPMM1RjHnrdKCZC9YSQcRh6HVB"
      ],
      "end": 1796473377.173528,
      "duration": 0.017128
    }
  ]
}
```

##### Response Headers

```http
Access-Control-Allow-Headers: *
Access-Control-Allow-Methods: OPTIONS, POST
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: ETag, Location
Allow: OPTIONS, POST
Cache-Control: no-cache, private
Content-Type: application/json; charset=utf-8
Date: Sat, 21 Nov 2026 10:43:14 GMT
Transfer-Encoding: chunked
X-Powered-By: Ember Nexus API
```

The short notation `{"name.keyword": "desc"}` and the long notation `{"name.keyword": {"order": "desc"}}` are
equivalent. `metadata.sort` contains the values the results were sorted by.

---

Home: [Ember Nexus API docs](/index.md)

Full site map: [llms.txt](/llms.txt)

Previous: [Sorting](/reference/search/elasticsearch-query-dsl-mixin/sorting.md)

Next: [Cypher path query](/reference/search/cypher-path-subset.md)
