oss-odm
Object document mapper for Open Search Server.
See also parent module node-oss-client.
Install
npm install oss-odm
Usage
const oss = ;const Index = Index; const index = name: 'my_index' indexers: oss searcher: oss; // Insert a new document in "my_index".index; // Search in "my_index".index;
new Index(options)
Create a new index with some options.
name
Type: String
Name of the index.
name: 'my_index' ;
lang
Type: String
Default language of the index, defaults to "ENGLISH".
lang: 'FRENCH';
indexers
Type: Array
or Object
OSS clients used to index document.
var indexer1 = oss;var indexer2 = oss; indexers: indexer1 indexer2 ;
searcher
Type: Object
OSS client used to search.
var searcher = oss; searcher ;
templates
Type: Object
Search templates that can be used in index.search
, the default template must be called "default".
All search options known by OSS can be specified in the template.
templates: default: returnedFields: 'id' 'title' searchFields: field: 'text' mode: 'TERM_AND_PHRASE' boost: 1 title: returnedFields: 'id' 'title' searchFields: field: 'title' mode: 'TERM_AND_PHRASE' boost: 1 ;
formatters
Type: Object
You can specify an input (indexing) and an output (search) formatters. These formatter are applied to each documents.
formatters: input: inputFormatter output: outputFormatter ; { // Add a timestamp key. documenttimestamp = Date; return document;} { // Convert id in Number. documentid = ; return document;}
filters
Type: Object
Filters formatter that can be used in index.search
.
filters: id: formatIdFilter ; { return type: 'QueryFilter' negative: false query: 'id:' + value ;}
joins
Type: Object
Joins that can be used in index.search
.
joins: myJoin: index: customIndex queryTemplate: 'customQueryTemplate' localField: 'local_id' foreignField: 'id' type: 'INNER' returnFields: false returnScores: false returnFacets: false ;
index.create(documents, [options], callback)
Insert a new document in the index.
Note : if an array is provided as value, it triggers a multi-valued field insertion.
index;
Some options are available:
lang
Type: String
The language of the document to index, default to the index language.
index;
index.destroy(values, [options], callback)
Destroy a documents in the index.
index;
Some options are available:
field
Type: String
The field used to match values, default to "id".
index;
index.search(query, [options], callback)
Search in the index.
index;
Some options are available:
lang
Type: String
The language used for searching documents.
index;
template
Type: String
The template used to process the query, defaults to "default".
index;
filters
Type: Object
Filters applied to the query. Filters are transformed using filter formatters defined in the constructor.
index;
joins
Type: Object
Joins applied to the query. Joins used the joins defined in the constructor.
index
OSS search options
All search options known by OSS can be used in the search function.
syncManager.sync(clients, schemas)
const indexer1 = oss;const indexer2 = oss; syncManager;
syncManager.drop(clients, names)
const indexer1 = oss;const indexer2 = oss; syncManager;
replicaManager.replicateAllIndexes(clients, schemas, cb)
Creates as many as replication indexes (based on schemas argument) on searchers passed as argument in clients and starts a replication on each of the searchers.
const indexer1 = oss;const indexes = name: 'my_index_1' name: 'my_index_2' replicaManager;
License
MIT