Setup Fields + Mappings
Searchkit has a CLI which helps creating a Elasticsearch schema for your documents and an example searchkit configuration to quickly get you started.
Copy the project from indexer example
Then within config.ts, add your own fields. Searchkit CLI will:
- generate a Elasticsearch mapping file based on your configuration
- Give you an example configuration for searchkit
- Update elasticsearch with the mapping file (requires host)
- Bulk index documents into elasticsearch (requires host, source and each field to have sourceOption path)
index: 'imdb_movies', // the elasticsearch index name
host: "http://localhost:9200", // host url for elasticsearch
apiKey: "cvdfv" // Optional. Elasticsearch apiKey for authentication. Requires write access to index
source: movies, //- Array of raw documents. Used with the field's sourceOptions. Optional
fieldName: 'type', // name of field. Must be lowercase
stored: true, // fields you want returned in the API.
facet: true, // If you want the value to be used as a facet
searchable: true // If you want the field to be searchable within query
type: 'integer' // Optional. Default is text. Can be `integer`, `date` or `float`
path: 'Type' // Used in indexing step. The key for the field value source.
transform: splitComma // Optional. To provide transformation from source to document field
Then run the CLI via
yarn start and follow the steps.
Generate Example Searchkit Config?
If yes, CLI will generate a file in current working directory called skConfig.md. This will provide you an elasticsearch mapping file and an example searchkit config, based on the field definitions within config.ts
Host detected. Destroy index and reinsert index mapping?
If yes, will recreate the elasticsearch index
Source detected. Insert documents into ES host?
If yes, will index the documents into elasticsearch