In IBM© Informix© 12.10.xC4, we added the ability to run text searches on JSON documents that are stored in Informix databases. You have three different ways of indexing and searching JSON documents:
- MongoDB API command: Run the ensureIndex command and specify text as the type of index, and then query with the MongoDB $text query operator. This method is appropriate if you don't want to change your existing MongoDB application, but provides limited options for indexing and querying.
- Informix extension to the MongoDB API: Run the createTextIndex command through the MongoDB API and then query with the Informix $ifxtext query operator. The createTextIndex command takes the same parameters as creating a basic text search index through SQL statements. This method is appropriate if you want to use MongoDB commands and also take advantage of the flexibility and power of Informix basic text search indexing and querying.
- Informix SQL statement: Create a basic text search index with JSON index parameters through SQL statements and query with the bts_contains() search predicate. This method is appropriate if you want to query JSON documents through SQL.
When you create a basic text search index on JSON documents, you can control the following aspects of the index:
Whether to index the documents as field name-value pairs so that you can search for text by field. Enable the all_json_names index parameter to index all field names. Set the json_names index parameters to index specific field names. You have the following choices to further refine how field name-value pairs are indexed:
- Whether to include JSON or BSON object paths in field name-value pairs so that you can search based on the field hierarchy in the document. Enable the json_path_processing index parameter to index paths.
- Whether to index the position of values in arrays so that you can search specific positions in arrays. Enable the json_array_processing index parameter to index the position of arrays.
- Whether to index as both field name-value pairs and unstructured text so that you have the flexibility to search a specific field or all fields. Enable the include_contents index parameter to include an unstructured index of field names and values.
- Whether an unstructured index contains only values and no field names so that you do not receive field names in search results. Enable the only_json_values index parameter to limit the unstructured index to values.
- Whether to ignore format errors for JSON or BSON documents. Enable the ignore_json_format_errors index parameter to ignore incorrectly formatted documents.
For more information, see: