SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
⤢ Open full site

Index and Search Text In a SAP HANA Cloud, data lake

Learn how to use and configure a text index on text columns in an SAP HANA Cloud, data lake. Then learn how to perform a text search on those columns when querying the data.

Overview

🎓 intermediate 60 min. SAP HANA Cloud, Data LakeIntermediateSAP HANA Cloud

You will learn

  • How to create a text index on a text column
  • How to perform a text search on a text column
  • How to understand text search scoring
Unknown U Unknown November 18, 2025
Created by March 22, 2022
Contributors

Prerequisites

Prerequisites

  • A provisioned SAP HANA Cloud, data lake
  • Access to an SAP HANA Cloud, data lake Files store
  • Access to the SAP Database Explorer
  • An installation of the HDLFSCLI

Steps

Intro

Searching long text for keywords may assist in filtering or analyzing important data from large data sets. Some data sets might have very large text columns where you do not know what words or partial words are contained. One good example is the GDELT data set. Today you will explore the events data from GDELT and learn how to use text search in an SAP HANA Cloud, data lake.


Step 1 Import the Data into a SAP HANA Cloud, data lake

To import the data into your SAP HANA Cloud, data lake (HDLRE) you first need the data files. SAP hosts some sample files that you can pull from Git to your local machine. Go to this GitHub repository and click the copy raw contents button.

Selecting Copy Raw Contents on the GitHub File.
Selecting Copy Raw Contents on the GitHub File.

Then create a local text file and paste the contents that were just copied. Save the text file as events_data.csv. Open a terminal or command prompt and navigate to the location of your file.

Terminal
cd <path_to_file>

Sample command prompt command for changing directories.
Sample command prompt command for changing directories.

Now, you can use your HDLFSCLI to put the data file into the SAP HANA Cloud, data lake File Store. If you haven’t set up your HDLFSCLI configuration yet, checkout the Getting Started with Data Lake Files HDLFSCLI tutorial. Use the HDLFSCLI upload command to upload the events_data.csv

Terminal
hdlfscli -config <your-hdl-files-config> upload events_data.csv events_data.csv

Sample HDLFSCLI upload command.
Sample HDLFSCLI upload command.

Now that you have your data file inside of your file container, you can move to SAP HANA Database Explorer and load the data into your HDL Relational Engine. The SAP HANA Database Explorer can be found in the BTP Cockpit or HANA Cloud Central under the ellipses on the HDLRE instance.

Locating the SAP HANA Database Explorer in HANA Cloud Central.
Locating the SAP HANA Database Explorer in HANA Cloud Central.

Once in the SAP HANA Database Explorer, open an SQL console for your HDLRE instance and paste the following SQL command. It will create the table structure needed to import the file in the file container.

SQL
CREATE TABLE EVENT (
    GlobalEventID INTEGER,    
    Day DATE,
    MonthYear INTEGER,
    Year INTEGER,
    FractionDate FLOAT,
    Actor1Code VARCHAR(27),
    Actor1Name VARCHAR(1024),
    Actor1CountryCode VARCHAR(3),
    Actor1KnownGroupCode VARCHAR(3),
    Actor1EthnicCode VARCHAR(3),
    Actor1Religion1Code VARCHAR(3),
    Actor1Religion2Code VARCHAR(3),
    Actor1Type1Code VARCHAR(3),
    Actor1Type2Code VARCHAR(3),
    Actor1Type3Code VARCHAR(3),
    Actor2Code VARCHAR(27),
    Actor2Name VARCHAR(1024),
    Actor2CountryCode VARCHAR(3),
    Actor2KnownGroupCode VARCHAR(3),
    Actor2EthnicCode VARCHAR(3),
    Actor2Religion1Code VARCHAR(3),
    Actor2Religion2Code VARCHAR(3),
    Actor2Type1Code VARCHAR(3),
    Actor2Type2Code VARCHAR(3),
    Actor2Type3Code VARCHAR(3),
    IsRootEvent INTEGER,
    EventCode VARCHAR(4),
    EventBaseCode VARCHAR(4),
    EventRootCode VARCHAR(4),
    QuadClass INTEGER,
    GoldsteinScale FLOAT,
    NumMentions INTEGER,
    NumSources INTEGER,
    NumArticles INTEGER,
    AvgTone FLOAT,
    Actor1Geo_Type INTEGER,
    Actor1Geo_FullName VARCHAR(120),
    Actor1Geo_CountryCode VARCHAR(2),
    Actor1Geo_ADM1Code VARCHAR(4),
    Actor1Geo_ADM2Code VARCHAR(64),
    Actor1Geo_Lat FLOAT,
    Actor1Geo_Long FLOAT,
    Actor1Geo_FeatureID VARCHAR(10),
    Actor2Geo_Type INTEGER,
    Actor2Geo_FullName VARCHAR(120),
    Actor2Geo_CountryCode VARCHAR(2),
    Actor2Geo_ADM1Code VARCHAR(4),
    Actor2Geo_ADM2Code VARCHAR(64),
    Actor2Geo_Lat FLOAT,
    Actor2Geo_Long FLOAT,
    Actor2Geo_FeatureID VARCHAR(10),
    ActionGeo_Type INTEGER,
    ActionGeo_FullName VARCHAR(120),
    ActionGeo_CountryCode VARCHAR(2),
    ActionGeo_ADM1Code VARCHAR(4),
    ActionGeo_ADM2Code VARCHAR(64),
    ActionGeo_Lat FLOAT,
    ActionGeo_Long FLOAT,
    ActionGeo_FeatureID VARCHAR(10),
    DateAdded DATETIME,
    SourceUrl VARCHAR(1024)
);

Once the table is created, proceed to load the data from the file.

SQL
LOAD TABLE EVENT (
    GlobalEventID,    
    "Day",
    MonthYear,
    "Year",
    FractionDate,
    Actor1Code,
    Actor1Name,
    Actor1CountryCode,
    Actor1KnownGroupCode,
    Actor1EthnicCode,
    Actor1Religion1Code,
    Actor1Religion2Code,
    Actor1Type1Code,
    Actor1Type2Code,
    Actor1Type3Code,
    Actor2Code,
    Actor2Name,
    Actor2CountryCode,
    Actor2KnownGroupCode,
    Actor2EthnicCode,
    Actor2Religion1Code,
    Actor2Religion2Code,
    Actor2Type1Code,
    Actor2Type2Code,
    Actor2Type3Code,
    IsRootEvent,
    EventCode,
    EventBaseCode,
    EventRootCode,
    QuadClass,
    GoldsteinScale,
    NumMentions,
    NumSources,
    NumArticles,
    AvgTone,
    Actor1Geo_Type,
    Actor1Geo_FullName,
    Actor1Geo_CountryCode,
    Actor1Geo_ADM1Code,
    Actor1Geo_ADM2Code,
    Actor1Geo_Lat,
    Actor1Geo_Long,
    Actor1Geo_FeatureID,
    Actor2Geo_Type,
    Actor2Geo_FullName,
    Actor2Geo_CountryCode,
    Actor2Geo_ADM1Code,
    Actor2Geo_ADM2Code,
    Actor2Geo_Lat,
    Actor2Geo_Long,
    Actor2Geo_FeatureID,
    ActionGeo_Type,
    ActionGeo_FullName,
    ActionGeo_CountryCode,
    ActionGeo_ADM1Code,
    ActionGeo_ADM2Code,
    ActionGeo_Lat,
    ActionGeo_Long,
    ActionGeo_FeatureID,
    DateAdded DATETIME('YYYYMMDDhhnnss'),
    SourceUrl
)
USING FILE 'hdlfs:///events_data.csv'
DELIMITED BY '\x09'
FORMAT CSV
ESCAPES OFF
QUOTES OFF;

Now, the data should be in the EVENTS table that was created earlier. Run a simple select statement to ensure it is there.

SQL
SELECT * FROM EVENT;
Step 2 Create a Text Index on a Text Column
+
Step 3 Query the Table Using the CONTAINS function
+
Step 4 Understanding the SCORE of a Text Index Search Result
+
Step 5 Knowledge check
+

Resources

Discussion

Share feedback on this tutorial or join the conversation in SAP Community.

Submit detailed feedback Discuss in Community
Steps
Step 1 of 5
1. Import the Data into a SAP HANA Cloud, data lake 2. Create a Text Index on a Text Column 3. Query the Table Using the CONTAINS function 4. Understanding the SCORE of a Text Index Search Result 5. Knowledge check

Learn more →