position.js 871 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: {
            x : {type : "integer"},
            y : {type : "integer"},
            tracking_id : {type : "integer"},
            date : {type : "date",
        format : "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
        seconds : {type : "float"}
        }
    }
    try {
        const resp = await addmappingToIndex('position', 'position_info', mapping);
        console.log(resp);
    } catch (e) {
        console.log(e);
    }
}

test();