Closed pulkitsinghal closed 8 years ago
It seems to me that after raising Issue #20, the solution provided for it in PR #23 by @fabien ... already had laid the groundwork for configuring and supporting each model with its own index. For example this became possible as a result of the work done at that time:
User = db.define('User', {
...
}, {
elasticsearch: {
index: red
}
});
Customer = db.define('Customer', {
...
}, {
elasticsearch: {
index: green
}
});
BUT there were several commits after that which may have undone some of the work!
For example this commit by @mrfelton makes changes under the assumption that there is only one index ... with that assumption:
So far reviewing the code and experimentation has shown me that calling setupIndices
instead of setupIndex
in ESConnector.prototype.connect
has no merit because the _models
array (modelClass
is looked up here by addDefaults
) is empty so essentially the same thing happens, no matter which method we call.
Maybe we can move the setup for index and mappings to run when Connector.prototype.define
is called? I searched github with keywords: connector call define user:strongloop extension:js and found several clues.
So I think overriding define
would be a bad idea because the framework that calls will not wait for any of the async operations like es-index-creation or es-mappings-creation to finish.
ESConnector.prototype.define = function(modelDefinition) {
var self = this;
// call parent method
ESConnector.super_.prototype.define.apply(self, arguments);
// add additional logic
// TODO: add indexes
// TODO: add mappings
// BUT above-TODO logic would be async whereas this code block will return right away!!!
// which adds a certain level of unpredictability if we accidently end up working on the model
// before indexes are created or mappings are done
};
To summarize scenario-A
:
automigrate
continues to leverage Connector._models
to take
care of everything in one fell swoop.I've decided to go with scenario-B
:
mappigns
array in datasource.<env>.json
may contain the index
and type
properties, which will be used to setup that model's index and mappings during connector initializationreleased in v1.1.0 on sept 15 2016
The goal is to implement and document how to use this connector with more than one index.