Read from an index layer
This example shows how to read partition metadata and partition data from an index layer on Node.js using HERE Data SDK for TypeScript.
Build and run an app on Node.js
Before you build an app, make sure that you installed all of the dependencies.
To build and run an app on Node.js:
-
Create an npm project.
mkdir example-app && cd example-app && npm init
-
Initialize a TypeScript project.
tsc --init
-
Install node types.
npm install --save-dev @types/node
-
Install the SDK modules.
npm install --save @here/olp-sdk-authentication @here/olp-sdk-dataservice-read @here/olp-sdk-dataservice-api
Now, everything is set to create the app.
-
Create the index.ts
file and app skeleton.
class App {
run() {
console.log("App works!");
}
}
const app = new App();
app.run();
-
Compile and run the app.
tsc && node .
After a successful run, the console displays the following message:
App works!
Create IndexLayerClient
You can use the IndexLayerClient
object to request any data and partition metadata from an index layer.
To create the IndexLayerClient
object:
-
Create the OlpClientSettings
object.
For instructions, see Create platform client settings.
-
Create the IndexLayerClient
object with IndexLayerClientParams
that contains the HERE Resource Name (HRN) of the catalog that contains the layer, layer ID, and platform client settings from step 1.
const indexLayerClient = await new IndexLayerClient({
catalogHrn: HRN.fromString("your-catalog-hrn"),
layerId: "your-layer-id",
settings: olpClientSettings,
});
Partition metadata from an index layer consists of the following information about the partition:
- ID (data handle)
- Data size
- Checksum
- Metadata
- Timestamp
To get partition metadata from the index layer:
-
Create the IndexLayerClient
object.
For instructions, see Create IndexLayerClient.
-
Create the IndexQueryRequest
object with the RSQL query string and, if the query string is huge, set the huge
boolean parameter to true
.
Note
The huge
parameter is optional, and its default value is false
.
const request = new IndexQueryRequest()
.withQueryString("RSQL string query")
.withHugeResponse(true);
-
Call the getPartitions
method with the IndexQueryRequest
parameter.
const partitions = await indexLayerClient.getPartitions(request);
You get the partition metadata filtered by the RSQL query.
In browser and Node.js, to abort requests before they have completed, you can create the AbortController
object, and then add the AbortController.signal
property to your requests. For more information, see the AbortController
documentation.
Example
const abortController = new AbortController();
const partitions = await indexLayerClient.getPartitions(request),
abortController.signal
);
Get data from an index layer
An index layer is an index of the catalog data by attributes. You can query the index layer to get the data handles of data that meets your query criteria, and you can then use these data handles to get the corresponding data.
To get data from the index layer:
-
Create the IndexLayerClient
object.
For instructions, see Create IndexLayerClient.
-
Call the getData
method with the data model that contains the ID property (also used as the data handle).
const data = await indexLayerClient.getData(model);
You receive data from the requested partition.
In browser and Node.js, to abort requests before they have completed, you can create the AbortController
object, and then add the AbortController.signal
property to your requests. For more information, see the AbortController
documentation.
Example
const abortController = new AbortController();
const data = await indexLayerClient.getData(model, abortController.signal);