Hi I am using monoosastic to connect my mongodb with elastic search. If I have data in mongodb the search is working fine but if the collection is empty I am getting error as index-not-found error in elastic search. below is my code
schema.plugin(mongoosastic, {
hosts: [ELASTICSEARCH_NODE],
index:ELASTICSEARCH_INDEX_NAME
});
setInterval(function () {
var stream = Model.synchronize();
var count = 0;
stream.on('data', function (err, doc) {
if (err) {
console.log('data error', err, doc);
}
count++;
});
stream.on('close', function () {
console.log('elastic search closed');
console.log('elastic search count -', count);
});
stream.on('error', function (err) {
console.log('elastic search error data', err);
});
}, 30000);
I tried changing the properties as below
schema.plugin(mongoosePaginate);
schema.plugin(mongoosastic, {
hosts: [ELASTICSEARCH_NODE],
index: ELASTICSEARCH_INDEX_NAME,
indexAutomatically:true,
customProperties:{
"persistent": {
"action.auto_create_index": "true"
}
}
});
But there is no change still facing the same error. Kindly help me with a solution.
Currently Elasticsearch will create auto index when you send data to elasticsearch if index is not exist. But when there is no data in mongodb then it will not send any request hence not creating any index.
To resolved this issue, Just Goto the Kibana dev console and execute below API command with index name (you can do same using Curl command as well). it will create index in Elasticsearch and then you will not face this issue.
PUT your_index_name