Rinku Kumar Rinku Kumar - 2 months ago 6
Node.js Question

Index getting created successful in Elasticsearch but docs.count getting 0

client.indices.delete({index: _index});

client.indices.create({
index: _index,
body: {
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 10
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings": {
"employee": {
"properties": {
"title": {
"type": "string",
"fields": {
"raw": {"type": "string", "index": "not_analyzed"}
}
},
"description": {
"type": "string",
"fields": {
"autocomplete": {"type": "string", "index_analyzer": "autocomplete"}
}
},
"interests": {
"type": "string"
},
"createdBy": {
"type": "string", "index": "not_analyzed"
},
}
}
}
}

}, function (error, response) {

var body = [];
Feed.find({},function(err, result){
if(err) throw err;
else{
var jdata = JSON.stringify(result);
var jsondata = JSON.parse(jdata);
// console.log("result>>>"+result);
jsondata.forEach(function(item){
body.push({"index": {"_index": _index, "_type": _type}});
body.push(item);
})
}
client.bulk({
body: body
}, function (err, resp) {
console.log('Indexing Completed!');
})
})
})
client.count({_index: 'company',_type: 'employee'},function(err,resp,status) {
console.log("constituencies",resp);
});

Answer

Now my problem is resolved......

In mongoose doc there is _id parameter.During the indexing of doc in elastic search it generate the by default _id. So yo need to give the path of _id in mapping. like

"_id": {
        "path": "_id"
        },