UDTs and Tuples

DSE Version: 6.0



Hello, I'm Joe Chu, and in this video we'll be talking about user defined types and tuples and how then work in DSE Search

Tuples and user defined types are a bit special when it comes to search due to the fact that there can be multiple values or fields within these data types. Fortunately, both of these are well defined, either when create the user defined type or when defining the table, in the case of tuples. This means that DSE knows all of the possible fields that a tuple or UDT column can have, and therefore will be much easier to query.

There is some special processing that needs to be done, and both the UDT / tuple column, and the fields within the column would be indexed as separate documents. This is not something you really need to concern yourself with, as DSE will automagically map these documents together. This includes the parent document, which includes the original column fields for a CQL row, and the child document, which represents the fields that exist within a UDT or tuple.

Here is an example user defined type and table that we will be using to demonstrate how to define the table in the search schema, and to execute searches with.

The user defined type is called metadata, and includes three fields. There is also a tuple column in the table definition called duration, and contains four fields.

When defining the search index schema to index a user-defined type or tuple, it will need to use the field type class - com.datasatax.bdp.search.solr.core.types.TupleField.

The column will need to be declared as field, and the individual fields within the column will also need to be declared separately as well, using a dot notation format to denote the column name and field name. If there are nested fields, then that will continue as column name dot field name 1 dot field name 2, and so forth. The name that you use for the tuple fields should correspond with the name in the CQL schema, and in the case of the tuple type, the name should be field1, field2, and so forth.

Here is an example of a field declaration for both the user defined type column and the tuple column.  Again note that the column is declared as a field, and then the individual fields within the column are also declared, using the column name and the field name.

The field type for the fields within the column should also correspond with the datatype from the CQL schema.

When searching in a UDT or tuple field, you'll need to make use of the tuple parser so that DSE knows how to search, and can be used in a normal search query or in the q or fq parameter for a JSON search query.

It is also possible to search in multiple fields within a UDT or tuple, as you can see in this first example. Even cooler is being able to search multiple UDT or tuple columns within a search query. Note that there are some syntax requirements to get this to work, which includes using parenthesis to group the search conditions together, to add a tuple parser for each separate column, and to avoid whitespace between the tuple parser and the search expression.

This final example demonstrates searching within a tuple column. Both search queries are the same, but the first one is shown as a basic search query, and the second as a JSON search query.

No write up.
No Exercises.
No FAQs.
No resources.
Comments are closed.