Short introduction for a nice feature to try from BigQuery
Enhancing BigQuery SEARCH features with SEARCH INDEX
A faster way to find text in unstructured text and semi-structured JSON
Recently, I started to explore the search indexes feature from BigQuery, which speeds up the search functionality a lot. The feature allows us to use SQL to find a specific word in the whole table fields in a faster way.

If you are familiar with the BigQuery string functions, then you may already use the CONTAINS_SUBSTR function to find a specific word that appears in the selected field. Then you now have a faster function with extra features.
The new feature facilitates text search using the SEARCH command, and it is faster than CONTAINS_SUBSTR because when you can create a search index on ALL COLUMNS, all STRING or JSON data the table will be indexed.
“BigQuery search indexes enable you to use Google Standard SQL to easily find unique data elements buried in unstructured text and semi-structured JSON data, without having to know the table schemas in advance.”
— GCP blog here.
Let’s try it together…
I am using a small football dataset, which contains 4 tables: players, clubs, countries, and transfers.
We will try first to use the CONTAINS_SUBSTR command to find a specific country:

You can take a note of the time consumed in reading the data, and also the accuracy of the results returned.
The command CONTAINS_SUBSTR(name, ‘oman’) here returned two results:
- Oman
- Romania
Let's search for a country under the countries table before indexing the SEARCH:

The command SEARCH(name, ‘oman’) here returned only one result:
- Oman
Implement the search indexing:
CREATE SEARCH INDEX countries_indexON `football.countries`(ALL COLUMNS);Now, let’s run the same SEARCH query again

As you can see, the time consumed in reading the data decreased dramatically.
We will try the same using more bigger table, transfers.
Find player Neymar using CONTAINS_SUBSTR command:

Find player Neymar using SEARCH command without indexing:

Implement SEARCH indexing
CREATE SEARCH INDEX player_name_indexON `football.transfers_all`(ALL COLUMNS);Find player Neymar using SEARCH command after indexing:

Hope this quick introduction can help you to explore the enhancements that you can implement on your BigQuery queries to speed up the search results.






