SODA Index Specifications (Reference)

The script content on this page is for navigation purposes only and does not alter the content in any way.

You can index the data in JSON documents using index specifications. A detailed definition of SODA index specifications is presented.

Note:

An index specification is a JSON object that specifies a particular kind of database index, which is used for operations on JSON documents. You can specify these kinds of index:

Each kind of index specification requires a name field, which is a string that names the index.

B-Tree Index Specifications

A SODA B-tree index specification specifies a B-tree function-based index on SQL/JSON function json_value, which is used by SODA to query JSON documents for scalar values. A B-tree index specification can have the following fields. Field fields is required for a B-tree index specification. The other fields are optional.

fields — Array of objects, each of which targets a field in the indexed documents that has a scalar JSON value. When the array has more than one element the index specification results in the creation of a composite B-tree index.

The order of the elements in array fields specifies the primary order of indexing, that is, the order among the targeted fields. The field of the first array element has the highest priority; the field of the last element has the lowest priority.

Each object in the array can have the following fields:

The default error-handling behavior is that the targeted field need not be present, but if it is present then its value must be a a JSON scalar that is convertible to data type datatype. An error is raised at query time if, for any document, that is not the case. In addition, if such an index exists, and you try to write a document where that is not the case, then an error is raised for the write operation.1

A B-tree index specification can specify an alternative error-handling behavior from the default by including field scalarRequired with a true value. That requires that the targeted field be present and have a value convertible to data type datatype. If, for any document to be indexed, that is not the case then an error is raised at indexing time. In addition, if such an index exists, and you try to write a document where that is not the case, then raise an error for the write operation.2

Note: A JSON null value in your data is always convertible to the data type specified for the index. That data is simply not indexed. (This is true regardless of the value of scalarRequired.)

Spatial Index Specifications

A SODA spatial index specification specifies an Oracle Spatial and Graph index, which indexes GeoJSON data. A spatial index specification has a spatial field, whose value is a string specifying the path to the JSON field to be indexed. The value of that targeted JSON field is expected to be a single GeoJSON geometry object, that is, a JSON scalar that is also a GeoJSON geometry object.

The default error-handling behavior is that the targeted field need not be present, but if it is present then its value must be a single GeoJSON geometry object. An error is raised at indexing time if, for any document to be indexed, that is not the case. In addition, if such an index exists, and you try to write a document where that is not the case, then an error is raised for the write operation.3

A spatial index specification can specify an alternative error-handling behavior from the default by including one of the following Boolean fields with a true value. (Only one of these error-handling fields can be specified as true; otherwise, a syntax error is raised at index-creation time.)

Note: If you have created a SODA spatial index for a field whose value is a GeoJSON geometry object, and if you use a QBE that targets that field, then the index can be picked up for the QBE only if both index and QBE specify the same error-handling behavior for that field. Both must specify the same one of these:

Search Index Specifications

A SODA search index specification specifies a JSON search index , which indexes the textual context of your JSON documents in a general way. A search index can improve the performance of both (1) ad hoc structural queries, that is, queries that you might not anticipate or use regularly, and (2) queries that make use of full-text search. It is an Oracle Text index that is designed specifically for use with JSON data.

A JSON search index can also accumulate and update aggregate information about your documents. In this it provides a JSON data guide , which is a summary of the structural and type information contained in a set of JSON documents. It records metadata about the fields used in those documents.

You can use data-guide information to:

The data-guide information contained in a JSON search index is updated automatically as new JSON content is added.

By default, a search index specification creates an index that provides both of these features: a general index and a data guide. These features are specified by fields search_on (string) and dataguide (string), respectively.

If field search_on is present with value "none" then the index provides only the data-guide functionality (no general search index). If field dataguide is present with value "off" then only the general search-index functionality is provided (no data-guide support). (A dataguide value of "on", or no field dataguide, specifies data-guide support).

Besides none, field search_on can also have value "text" or "text_value". Both of these support full-text queries, which use QBE operator $contains, and they both support ad hoc queries that make of other QBE operators, such as $eq, $ne, and $gt.

In addition, search_on value "text_value" indexes numeric ranges. This is a separate value because it has an added performance cost. If you do not need range indexing then you can save some index maintenance time and some disk space by specifying value text instead of text_value. The default value of search_on is text_value.

See Also:

Related Topics

  1. The default error-handling behavior corresponds to the use of SQL clauses ERROR ON ERROR and NULL ON EMPTY for a functional index created on a json_value expression. 

  2. A true value of scalarRequired corresponds to the use of SQL clause ERROR ON ERROR for a functional index created on a json_value expression. 

  3. The default error-handling behavior corresponds to the use of SQL clauses ERROR ON ERROR and NULL ON EMPTY for a functional index created on a json_value expression. 

  4. A true value of scalarRequired corresponds to the use of SQL clause ERROR ON ERROR for a functional index created on a json_value expression. 

  5. A true value of lax corresponds to the use of SQL clause NULL ON ERROR for a functional index created on a json_value expression.