Search and Visualize Data using Oracle Cloud Infrastructure Search with OpenSearch
Introduction
Oracle Cloud Infrastructure (OCI) Search with OpenSearch is an insight engine offered as an Oracle-managed service. With OCI’s capabilities for OpenSearch and OpenSearch Dashboards, you can store, search, and analyze large volumes of data quickly and see results in near real-time. Oracle automates, without any downtime, activities that include patching, updating, upgrading, backing-up, and resizing of the service.
Objectives
-
Understand the prerequisites for the creation of a search cluster.
-
Create an OpenSearch cluster, connect to the cluster and ingest data.
-
Run sample search commands.
-
Visualize data in OpenSearch dashboards.
Prerequisites
-
Create the required service policies in the OCI Console. Change
any-user
to your desired group, and provide the path to the compartment if required.Working policies:
Allow group SearchOpenSearchAdmins to manage vnics in compartment <NETWORK_RESOURCES_COMPARTMENT> Allow group SearchOpenSearchAdmins to manage vcns in compartment <NETWORK_RESOURCES_COMPARTMENT> Allow group SearchOpenSearchAdmins to manage subnets in compartment <NETWORK_RESOURCES_COMPARTMENT> Allow group SearchOpenSearchAdmins to use network-security-groups in compartment <NETWORK_RESOURCES_COMPARTMENT> Allow group SearchOpenSearchAdmins to manage opensearch-family in compartment <CLUSTER_RESOURCES_COMPARTMENT>
-
Create a VCN with a public subnet and a private subnet.
-
Simplified Process:
-
Go to the OCI Console and open the navigation menu.
-
Click Networking and Virtual Cloud Networks.
-
Click Start VCN Wizard and Create VCN with Internet Connectivity.
-
-
Custom Process:
-
Go to the OCI Console and open the navigation menu.
-
Click Networking and Virtual Cloud Networks.
-
Click Create VCN and enter your own desired details.
-
-
-
Create a virtual machine (VM) instance in the public subnet of the VCN.
-
Go to the OCI Console and open the navigation menu.
-
Click Compute and Instances.
-
Click Create instance.
-
Enter the Name and select the compartment.
-
In the Image and shape section, use the default values (Oracle Linux 8, VM.Standard.E4.Flex).
-
In the Networking section, select the public subnet and assign a public IP.
-
In the Add SSH keys section, decide whether you want to use an existing SSH key, or generate a new SSH key. If you select to generate a new SSH key, remember to download the key.
-
Note: In this tutorial, a Mac and an Oracle Linux instance were used. Windows command line instructions may differ.
Task 1: Create an OCI Search Service Cluster
-
Go to the OCI Console, navigate to Databases, OCI Search Service, Clusters and click Create cluster. Enter the cluster name and compartment where you want to create the cluster and click Next.
-
Select the cluster size and click Next.
-
Select the VCN, the private subnet create in Prerequisites section and click Next.
After the cluster creation, in the OCI Search service cluster details page, note the API endpoints and the IP addresses which you can alternatively use.
Task 2: Create Security Rules in the VCN Security List
In the VCN, create a security list with the following security rules. Alternatively, they can be added to the VCN default security list.
-
In the Virtual cloud network details page, click Security Lists, Security List and Add Ingress Rules.
Note: Add a rule for port
9200
(OpenSearch), and a rule for5601
(OpenSearch Dashboards).
Task 3: Test the Connection to OCI Search Service – OpenSearch Endpoint
You can use one of the following options.
Option 1: From Within the Created VM Instance
-
Connect to the instance using SSH.
ssh -i ~/.ssh/id_rsa_opensearch.key opc@<your_VM_instance_public_IP>
-
Run one of the following commands.
curl https://mycluster.opensearch.us.example.com:9200 # OpenSearch API endpoint example
Or
curl https://<your_opensearch_private_IP>:9200 --insecure # OpenSearch private IP example
Option 2: From your Local Machine, through Port Forwarding
-
Run the following port forwarding SSH command in the terminal. Do not close the terminal to ensure that the connection remains active.
ssh -C -v -t -L 127.0.0.1:5601:<your_opensearch_dashboards_private_IP>:5601 -L 127.0.0.1:9200:<your_opensearch_private_IP>:9200 opc@<your_VM_instance_public_IP> -i <path_to_your_private_key>
-
Open a new terminal window and run the following command.
curl https://localhost:9200 --insecure
If the steps are performed correctly you should see a response as follows, regardless of the option used.
{
"name" : "opensearch-master-0",
"cluster_name" : "opensearch",
"cluster_uuid" : "M6gclrE3QLGEBlkdme8JkQ",
"version" : {
"distribution" : "opensearch",
"number" : "1.2.4-SNAPSHOT",
"build_type" : "tar",
"build_hash" : "e505b10357c03ae8d26d675172402f2f2144ef0f",
"build_date" : "2022-02-08T16:44:39.596468Z",
"build_snapshot" : true,
"lucene_version" : "8.10.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "The OpenSearch Project: https://opensearch.org/"
}
Task 4: Ingest Data
Run the following commands from within your VM instance.
-
Download the sample data set.
curl -O https://raw.githubusercontent.com/oracle-livelabs/oci/main/oci-opensearch/files/OCI_services.json
-
Create mapping (optional). If you do not run this command or any variation of it, a default mapping will be automatically created.
curl -XPUT "https://mycluster.opensearch.us.example.com:9200/oci" -H 'Content-Type: application/json' -d' { "mappings": { "properties": { "id": {"type": "integer"}, "category": {"type": "keyword"}, "text": {"type": "text"}, "title": {"type": "text"}, "url": {"type": "text"} } } } '
-
Push the data set.
curl -H 'Content-Type: application/x-ndjson' -XPOST "https://<your_opensearch_private_IP>:9200/oci/_bulk?pretty" --data-binary @OCI_services.json
-
Check your indices.
curl "https://mycluster.opensearch.us.example.com:9200/_cat/indices" # OpenSearch API endpoint example
curl -X GET "https://<your_opensearch_private_IP>:9200/_cat/indices" --insecure # OpenSearch private IP example
Task 5: Query the OCI Search Service – Sample Search Query
You can use one of the following options.
Option 1: From the VM Instance Shell
curl -X GET "https://mycluster.opensearch.us.example.com:9200/oci/_search?q=title:Kubernetes&pretty"
# OpenSearch API endpoint example
curl -X GET "https://<your_opensearch_private_IP>:9200/oci/_search?q=title:Kubernetes&pretty"
# OpenSearch private IP example
Option 2: From your Local Terminal, After Port Forwarding
curl -X GET "https://localhost:9200/oci/_search?q=title:Kubernetes&pretty" --insecure
Option 3: From your Local browser, After Port Forwarding
https://localhost:9200/oci/_search?q=title:Kubernetes&pretty
For more information about query syntax, see the OpenSearch or Elasticsearch tutorials.
Task 6: Connect to OpenSearch Dashboards
-
From your local machine, through port forwarding.
Note: Skip this step if you have already run it in the previous steps and the connection is still open.
ssh -C -v -t -L 127.0.0.1:5601:<your_opensearch_dashboards_private_IP>:5601 -L 127.0.0.1:9200:<your_opensearch_private_IP>:9200 opc@<your_instance_public_ip> -i <path_to_your_private_key>
-
Access
https://localhost:5601
in your browser.Note: Currently, depending on the browser, a warning message similar to Your connection is not private is displayed. Select the option which allows you to proceed anyway.
Task 7: Search and Visualize Data in OpenSearch Dashboards
-
With the port forwarding connection in place, access
https://localhost:5601
in your browser. -
Open the OpenSearch Dashboards navigation menu.
-
Navigate to Management, Stack Management and click Index Patterns. Create an index pattern with name
oci
. -
Go to the OpenSearch Dashboards menu and click Discover to use the OpenSearch Dashboards UI to search your data.
-
Go to the OpenSearch Dashboards menu, click Dashboards and follow these steps to create a sample pie chart.
-
Click Create new, New Visualization and Pie.
-
Select
oci
as Source. -
In Buckets, click Add and expand Split slices. Enter the information showing in the following image and click Update.
-
Related Links
Acknowledgments
-
Author - Nuno Goncalves (Senior Principal Product Manager)
-
Contributor - Jordan Oliver (Principal Product Manager)
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Search and Visualize Data using Oracle Cloud Infrastructure Search with OpenSearch
F56572-05
October 2024