최동원

ealsticsearch

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();
\ No newline at end of file
const axios = require("axios");
const log = console.log;
const esClient = require('./client');
const fs = require('fs');
async function indexData() {
try {
const aptRaw = await fs.readFileSync('./count.json');
const aptInfo = JSON.parse(aptRaw);
const apt_list = []
for(const item of aptInfo.data){
const tmp_data = {
date : item.time.substring(0,19),
current_count : item.now,
total_count : item.total,
seconds : item.s
}
apt_list.push(tmp_data)
}
const body = apt_list.flatMap(doc => [{ index: { _index: 'count', _type: 'count_info' } }, doc])
const { body: bulkResponse } = await esClient.bulk({ refresh: true, body })
if (bulkResponse.errors) {
const erroredDocuments = []
bulkResponse.items.forEach((action, i) => {
const operation = Object.keys(action)[0]
if (action[operation].error) {
erroredDocuments.push({
status: action[operation].status,
error: action[operation].error,
operation: body[i * 2],
document: body[i * 2 + 1]
})
}
})
console.log(erroredDocuments)
log('bulk error')
}
} catch (error) {
log('에러')
}
}
indexData();
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();
\ No newline at end of file
const axios = require("axios");
const log = console.log;
const esClient = require('./client');
const fs = require('fs');
async function indexData() {
try {
const aptRaw = await fs.readFileSync('./position.json');
const aptInfo = JSON.parse(aptRaw);
const apt_list = []
for(const item of aptInfo.data){
const tmp_data = {
x : item.x,
y : item.y,
tracking_id : item.id,
date : item.time.substring(0,19),
seconds : item.s
}
apt_list.push(tmp_data)
}
const body = apt_list.flatMap(doc => [{ index: { _index: 'position', _type: 'position_info' } }, doc])
const { body: bulkResponse } = await esClient.bulk({ refresh: true, body })
if (bulkResponse.errors) {
const erroredDocuments = []
bulkResponse.items.forEach((action, i) => {
const operation = Object.keys(action)[0]
if (action[operation].error) {
erroredDocuments.push({
status: action[operation].status,
error: action[operation].error,
operation: body[i * 2],
document: body[i * 2 + 1]
})
}
})
console.log(erroredDocuments)
log('bulk error')
}
} catch (error) {
log('에러')
}
}
indexData();