Skip to main content
To learn how to configure an index for a JSON column, watch the following video, or complete the tutorial below.

Prerequisites

To follow the code examples in this guide, you must install Docker locally and download recipes.
  1. If you haven’t already, download recipes.
  2. In terminal, go to the recipe by running the following command:

Launch Pinot Cluster

You can spin up a Pinot Cluster by running the following command:
This command will run a single instance of the Pinot Controller, Pinot Server, Pinot Broker, Kafka, and Zookeeper. You can find the docker-compose.yml file on GitHub.

Data generator

This recipe contains a data generator that creates events with data about people. It uses the Faker library, so you’ll first need to install that:
You can generate data by running the following command:
Output is shown below:

Kafka ingestion

We’re going to ingest this data into an Apache Kafka topic using the kcat command line tool. We’ll also use jq to structure the data in the key:payload structure that Kafka expects:
We can check that Kafka has some data by running the following command:
We’ll see something like the following:

Pinot Schema and Table

Now let’s create a Pinot Schema and Table. First, the schema:
Our schema has only two columns - one for the timestamp and another one that stores the person. Now for the table config:
This highlighted section contains the config for the JSON index. An explanation of each of the config parameters is shown below: So we are including all fields except age in the JSON index.
Fields included in the JSON index can be filtered using the JSON_MATCH function. If you use this function with a field that isn’t included in the index, it won’t return any records.
We’ll create the table by running the following:

Querying by JSON index

Let’s now try to query this table using the JSON index. JSON indexes support the following predicates: =, <>, IN, and NOT IN

State = Kentucky

Query Results

State <\> Kentucky

Query Results

State IN Kentucky or Alabama

Query Results

State NOT IN Kentucky or Alabama

Query Results

Unindexed field

What if we try to query by the age column, which hasn’t been indexed?
Query Results We get back no results! We can even run the following query to confirm that the table contains records with an age of 59:
Query Results