Example with pagination and sorting

Simple query with pagination and sorting examples

Mapping

{
  "id": { "type": "keyword" },
  "name": { "type": "text" },
  "price": { "type": "float" },
  "expiresAt": { "type": "date" }
}

Documents

{
  "documents": [
    {
      "id": "1",
      "name": "Milk, 1.5 l",
      "price": 9.8,
      "expiresAt": "2021-12-03T03:00:00Z"
    },
    {
      "id": "2",
      "name": "Milk, 1.25 l",
      "price": 8.9,
      "expiresAt": "2021-12-04T03:00:00Z"
    },
    {
      "id": "3",
      "name": "Chocolate Milk",
      "price": 3.2,
      "expiresAt": "2021-11-12T08:00:00Z"
    },
    {
      "id": "4",
      "name": "Bread",
      "price": 2.99,
      "expiresAt": "2021-10-30T05:00:00Z"
    },
    {
      "id": "5",
      "name": "Banana Milk Drink",
      "price": 3.39,
      "expiresAt": "2022-01-30T01:00:00Z"
    },
    {
      "id": "6",
      "name": "Hard Cheese",
      "price": 4.44,
      "expiresAt": "2022-02-15T00:00:00Z"
    },
    {
      "id": "7",
      "name": "Chocolate Curd Snack",
      "price": 2.17,
      "expiresAt": "2021-12-24T12:00:00Z"
    },
    {
      "id": "8",
      "name": "Toasted Bread",
      "price": 2.99,
      "expiresAt": "2021-10-30T05:00:00Z"
    },
    {
      "id": "9",
      "name": "Coconut Milk",
      "price": 1.99,
      "expiresAt": "2021-09-24T13:30:00Z"
    },
    {
      "id": "10",
      "name": "Milk, 0.5 l",
      "price": 1.99,
      "expiresAt": "2021-09-24T13:30:00Z"
    },
    {
      "id": "11",
      "name": "Almond Milk, 0.75 l",
      "price": 10.79,
      "expiresAt": "2022-03-12T14:00:00Z"
    },
    {
      "id": "12",
      "name": "Almond Milk, 0.95 l",
      "price": 12.89,
      "expiresAt": "2022-03-12T14:00:00Z"
    },
    {
      "id": "13",
      "name": "Strawberry Milk Drink, 0.75 l",
      "price": 1.99,
      "expiresAt": "2021-09-26T13:30:00Z"
    }
  ]
}

Query Configuration

{
  "description": "Food query",
  "configuration": {
    "queryFields": {
      "name": 1
    },
    "match": "all",
    "selectFields": ["id", "name", "price", "expiresAt"]
  },
  "debugMode": true
}

Public Query

Limit

Request:

{
  "searchText": "milk",
  "limit": 4
}

Response:

{
  "searchText": "milk",
  "total": 9,
  "items": [
    {
      "id": "3",
      "name": "Chocolate Milk",
      "price": 3.2,
      "expiresAt": "2021-11-12T08:00:00Z"
    },
    {
      "id": "9",
      "name": "Coconut Milk",
      "price": 1.99,
      "expiresAt": "2021-09-24T13:30:00Z"
    },
    {
      "id": "1",
      "name": "Milk, 1.5 l",
      "price": 9.8,
      "expiresAt": "2021-12-03T03:00:00Z"
    },
    {
      "id": "2",
      "name": "Milk, 1.25 l",
      "price": 8.9,
      "expiresAt": "2021-12-04T03:00:00Z"
    }
  ],
  "facets": [],
  "filters": {},
  "limit": 4,
  "metadata": {}
}

Pagination - second page

Request:

{
  "searchText": "milk",
  "limit": 4,
  "offset": 4
}

Response:

{
  "searchText": "milk",
  "total": 9,
  "items": [
    {
      "id": "5",
      "name": "Banana Milk Drink",
      "price": 3.39,
      "expiresAt": "2022-01-30T01:00:00Z"
    },
    {
      "id": "10",
      "name": "Milk, 0.5 l",
      "price": 1.99,
      "expiresAt": "2021-09-24T13:30:00Z"
    },
    {
      "id": "11",
      "name": "Almond Milk, 0.75 l",
      "price": 10.79,
      "expiresAt": "2022-03-12T14:00:00Z"
    },
    {
      "id": "12",
      "name": "Almond Milk, 0.95 l",
      "price": 12.89,
      "expiresAt": "2022-03-12T14:00:00Z"
    }
  ],
  "facets": [],
  "filters": {},
  "limit": 4,
  "offset": 4,
  "metadata": {}
}

Sorting

Request:

{
  "searchText": "p",
  "limit": 5,
  "sort": [
    {
      "price": "asc"
    }
  ]
}

Response:

{
  "searchText": "m",
  "total": 9,
  "items": [
    {
      "id": "9",
      "name": "Coconut Milk",
      "price": 1.99,
      "expiresAt": "2021-09-24T13:30:00Z"
    },
    {
      "id": "10",
      "name": "Milk, 0.5 l",
      "price": 1.99,
      "expiresAt": "2021-09-24T13:30:00Z"
    },
    {
      "id": "13",
      "name": "Strawberry Milk Drink, 0.75 l",
      "price": 1.99,
      "expiresAt": "2021-09-26T13:30:00Z"
    },
    {
      "id": "3",
      "name": "Chocolate Milk",
      "price": 3.2,
      "expiresAt": "2021-11-12T08:00:00Z"
    },
    {
      "id": "5",
      "name": "Banana Milk Drink",
      "price": 3.39,
      "expiresAt": "2022-01-30T01:00:00Z"
    }
  ],
  "facets": [],
  "filters": {},
  "limit": 5,
  "metadata": {}
}

Sorting - multiple fields

Request:

{
  "searchText": "m",
  "limit": 5,
  "sort": [
    {
      "price": "asc"
    },
    {
      "expiresAt": "desc"
    }
  ]
}

Response:

{
  "searchText": "m",
  "total": 9,
  "items": [
    {
      "id": "13",
      "name": "Strawberry Milk Drink, 0.75 l",
      "price": 1.99,
      "expiresAt": "2021-09-26T13:30:00Z"
    },
    {
      "id": "9",
      "name": "Coconut Milk",
      "price": 1.99,
      "expiresAt": "2021-09-24T13:30:00Z"
    },
    {
      "id": "10",
      "name": "Milk, 0.5 l",
      "price": 1.99,
      "expiresAt": "2021-09-24T13:30:00Z"
    },
    {
      "id": "3",
      "name": "Chocolate Milk",
      "price": 3.2,
      "expiresAt": "2021-11-12T08:00:00Z"
    },
    {
      "id": "5",
      "name": "Banana Milk Drink",
      "price": 3.39,
      "expiresAt": "2022-01-30T01:00:00Z"
    }
  ],
  "facets": [],
  "filters": {},
  "limit": 5,
  "metadata": {}
}