count.js
845 Bytes
const esClient = require('./client');
const addmappingToIndex = async function(indexName, mappingType, mapping){
console.log(mapping);
return await esClient.indices.putMapping({
index: indexName,
type: mappingType,
body: mapping
});
}
module.exports = addmappingToIndex;
// test function to explain how to invoke.
async function test() {
const mapping = {
properties: {
date : {type : "date",
format : "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
current_count : {type : "integer"},
total_count : {type : "integer"},
seconds : {type : "float"}
}
}
try {
const resp = await addmappingToIndex('count', 'count_info', mapping);
console.log(resp);
} catch (e) {
console.log(e);
}
}
test();