Subsurface data management: How to search for data within OSDU on AWS Sandbox
In the previous blog we explained how to authenticate to your OSDU on AWS sandbox. After you have successfully authenticated, you might want to interact with the data stored on your OSDU on AWS sandbox. This is the second blog post in a series that provides support for getting started with your OSDU on AWS environment.
Overview of Solution
This blog explains how to search for data within OSDU on AWS Sandbox. We will use the Node.js application created in the previous blog How to authenticate OSDU on AWS sandbox.
- OSDU R2 installed and configured in an AWS account.
- TNO and Volve data loaded into the AWS account where you installed OSDU R2.
- Download and install Node.js.
- Download and install Visual Studio Code IDE.
- Completion of blog How to authenticate OSDU on AWS sandbox.
Open the Node.js application that you created for the authentication blog in Visual Studio Code.
- Open Visual Studio Code Open the folder where you created the Node.js package for the authentication blog.
- Add Search API code to the index.js file
In this code, replace the
<OSDU API UrL> with your Amazon API Gateway URL.
- Call this Search API function just after you receive the token.
Add the following code just after console.log statement for access token.
- Run the index.js on the VS Code terminal
- The example returns three results that match our query where Wellbore ID (data.Data.IndividualTypeProperties.WellboreID) is 7444 (srn:master-data/Wellbore:7444:). We also mentioned kind as “opendes:osdu:*:0.2.0” that returns any kind within opendes:osdu partition and source name. You will see the search results as shown.
- If you wanted to get a specific kind, you could have used a query like the following one. The difference between the previous query and the following one is the * is replaced by welllog-wpc specifically asking for well log work product component.
The CallSearchApi function takes the token as a parameter and posts the search data to the OSDU search URL using axios library. The following code specifies what kind of record needs to be searched, and the query. You can use * format for wild-card searches and it can be used on any of the four kind colon separated parts. You can use Apache Lucene syntax for the query.
For more information on using the query syntax, please see OSDU R2 query syntax
Then, instantiate a Node.js https.agent class which is responsible for managing connection persistence and reuse of HTTP clients. The argument rejectUnauthorized: true is set during instantiation to reject SSL issues.
Then, post the search request to the OSDU search URL. Using the axios library, create an instance of the axios object that will be used to send the post request to the search API. Add the Authorization, Content-Type and the data-partion-id to the headers of the post request.
Then, pass the successful response returned by the OSDU Search API to the then() function that prints the search results. The search results response object has a totalCount property that can be used to see how many data components are being returned. The code then goes through each of the data components and prints them on the console. If there are any errors, we print them on the console in the catch() function.