Schema

更新时间:
复制 MD 格式

A schema defines the data structure of an OpenSearch application. It specifies which tables store your data, how fields are typed within those tables, and which fields are indexed for full-text search or filtering.

All configuration lives under two top-level keys: tables (your data) and indexes (how that data is searchable).

Schema structure

FieldTypeDescription
tablesObjectThe tables in the application. Each key under tables is a table name.
tables.*ObjectThe definition of a table. See Table.
indexesObjectThe index configuration for the application. See Index.

Example

{
    "tables": {
        "main": {
            "primaryTable": true,
            "name": "main",
            "fields": {
                "id": {
                    "name": "id",
                    "type": "LITERAL",
                    "primaryKey": true
                },
                "title": {
                    "name": "title",
                    "type": "TEXT",
                    "primaryKey": false
                },
                "buy": {
                    "name": "buy",
                    "type": "INT",
                    "primaryKey": false
                },
                "cate_id": {
                    "name": "cate_id",
                    "type": "INT",
                    "primaryKey": false
                },
                "cate_name": {
                    "name": "cate_name",
                    "type": "LITERAL",
                    "primaryKey": false
                }
            }
        }
    },
    "indexes": {
        "searchFields": {
            "id": {
                "fields": [
                    "id"
                ]
            },
            "default": {
                "fields": [
                    "title"
                ],
                "analyzer": "chn_standard"
            },
            "cate_name": {
                "fields": [
                    "cate_name"
                ]
            }
        },
        "filterFields": [
            "id",
            "buy",
            "cate_id",
            "cate_name"
        ]
    }
}

Table

A table maps to a data source in your application. One table must be designated as the primary table.

FieldTypeDescription
nameStringThe name of the table.
primaryTableBooleanIndicates whether the table is the primary table.
fieldsObjectThe fields in the table. Each key under fields is a field name.
fields.*ObjectThe definition of a field. See Field.

Example

{
    "primaryTable": true,
    "name": "main",
    "fields": {
        "id": {
            "name": "id",
            "type": "LITERAL",
            "primaryKey": true
        },
        "title": {
            "name": "title",
            "type": "TEXT",
            "primaryKey": false
        },
        "buy": {
            "name": "buy",
            "type": "INT",
            "primaryKey": false
        },
        "cate_id": {
            "name": "cate_id",
            "type": "INT",
            "primaryKey": false
        },
        "cate_name": {
            "name": "cate_name",
            "type": "LITERAL",
            "primaryKey": false
        }
    }
}

Field

A field represents a column in your table. Its type determines how the data is stored and which index operations are supported.

FieldTypeDescription
nameStringThe name of the field.
typeStringThe data type of the field. For supported types, see Schema of tables for Industry Algorithm Edition.
primaryKeyBooleanIndicates whether the field is a primary key field.
joinWithArrayThe tables that are joined to external tables.

Example

{
    "type": "INT",
    "name": "id",
    "primaryKey": true,
    "joinWith": ["other_table"]
}

Index

The indexes object controls two types of indexing:

  • `searchFields`: Fields indexed for full-text search. Use these when you need to search across text content.

  • `filterFields`: Fields indexed as attributes for filtering and sorting. Use these for numeric comparisons, category filtering, and range queries.

FieldTypeDescription
searchFieldsObjectIndex fields for full-text search. Each key is an index field name.
searchFields.*ObjectThe definition of a search index field. See Search field.
filterFieldsArrayField names to index as attribute (filter) fields.

Example

{
    "searchFields": {
        "default": {
            "fields": [
                "title"
            ],
            "analyzer": "chn_standard"
        },
        "id": {
            "fields": [
                "id"
            ]
        }
    },
    "filterFields": [
        "id"
    ]
}

Search field

A search field defines how one or more table fields are combined into a single full-text index.

FieldTypeDescription
fieldsArrayThe list of index fields.
analyzerStringThe name of the analyzer, such as a custom analyzer or built-in analyzer. For custom analyzers, see Custom analyzers. For built-in options, see Built-in analyzers.

Example

{
    "fields": ["title"],
    "analyzer": "chn_standard"
}

Built-in analyzers

Choose an analyzer based on the language and search behavior you need.

AnalyzerUse when
chn_standardSearching Chinese text in general scenarios (e-commerce, news, documentation).
simpleSearching content in specific scenarios using basic tokenization.
chn_singleSearching by individual Chinese characters, such as for character-level matching.
eng_standardSearching English text with stemming — running matches run, runs, and ran.
eng_nostemSearching English text while retaining the roots of words.
fuzzyTolerating minor spelling variations and typos in search queries.
keywordMatching the exact string without any tokenization — suitable for IDs, codes, and tags.
chn_ecommerceSearching product names, SKUs, and descriptions in Chinese e-commerce contexts.
chn_filmSearching Chinese titles, cast names, and descriptions in video or media contexts.
chn_scene_nameRecognizing and matching Chinese person names.
chn_scene_orgRecognizing and matching Chinese organization names.
first_letterSearching by the first letter of each pinyin syllable (simple pinyin spelling).
full_pinyinSearching by the full pinyin spelling of Chinese characters.
numericPerforming range searches on numeric values.
geoPerforming range searches based on geographical location.
chn_it_contentSearching Chinese technical content, such as IT documentation and product descriptions.