Pagination

In order to help clients organize query and discovery requests with a large number of responses (for example, think of how costly could be returning a query matching 1,000,000 results in a single HTTP response to a queryContext request), queryContext (and related convenience operations) and discoverContextAvailability (and related convenience operations) allow pagination. The mechanism is based on three URI parameters:

Result are returned ordered by increasing entity/registration creation time. This is to ensure that if a new entity/registration is created while the client is going through all the results the new results are added at the end (thus avoiding duplication results).

Let’s illustrate with an example: a given client cannot process more than 100 results in a single response and the queryContext includes a total of 322 results. The client could do the following (only URL is included, for the sake of completeness).

POST <orion_host>:1026/v1/queryContext?limit=100&details=on
...
(The first 100 elements are returned, along with the following errorCode in the response, 
which allows the client to know how many entities are in sum and, therefore, the number of 
subsequence queries to do)

  <errorCode>
    <code>200</code>
    <reasonPhrase>OK</reasonPhrase>
    <details>Count: 322</details>
  </errorCode>

POST <orion_host>:1026/v1/queryContext?offset=100&limit=100
...
(Entities from 101 to 200)

POST <orion_host>:1026/v1/queryContext?offset=200&limit=100
...
(Entities from 201 to 300)

POST <orion_host>:1026/v1/queryContext?offset=300&limit=100
...
(Entities from 301 to 222)

Note that if the request uses an “out of bound” offset you will get a 404 NGSI error, as shown below:

POST <orion_host>:1026/v1/queryContext?offset=1000&limit=100
...
<queryContextResponse>
  <errorCode>
    <code>404</code>
    <reasonPhrase>No context element found</reasonPhrase>
    <details>Number of matching entities: 5. Offset is 1000</details>
  </errorCode>
</queryContextResponse>