使用N个数字文档创建弹性搜索N个数字

时间:2018-03-28 11:56:13

标签: javascript elasticsearch elasticsearch-plugin elasticsearch-5 elasticsearch-6

我试图为每个索引创建包含2000个文档的365个索引。我也很乐意设置为index => "test-%{+YYYY.MM.dd}" - 每天都有新数据。实际上,我需要模拟每天索引的创建,其中每个索引有大约2000条记录。我使用的是elasticsearch 6.2。

export const initTest = async types => {
    try {
        let client = createClient()

        const templateSettings = {
            index_patterns : ['*'],
            settings: indexTemplateSettings,
            mappings : types.reduce((p, type) => ({
                ...p,
                [type] : {
                    'numeric_detection': true,
                    _source : {enabled : true},
                },
            }), {}),
        }

        await client.indices.putTemplate({
            name: 'default',
            body: templateSettings,
        },(error, response) => {
            logger.silly('Pushing of index template completed', response)
        })
    } catch (e) {
        logger.error(e)
    }
}

export const pushTest = (message, type, index) => new Promise(async resolve => {
    try {
        let client = createClient()

        await initTest(['Call'])

        await client.index({
            index: `${YYYY.MM.dd}`, //per day new data
            type,
            body: message,
        },
        (error, response) => {
            logger.silly('Pushing of data completed', response)

            resolve(response)
        })
    } catch (e) {
        logger.error(e)
    }
})


for (let index = 0; index < 365; index++) {

    let messageTest

    for (let documents = 0; documents < 2000; documents++) {

        messageTest = {

            location: `Room_${Math.floor(Math.random() * 100)}`,
            zone: `Zone_${Math.floor(Math.random() * 100)}`,
            personName: 'person name',
            personRoom: `Room_${Math.floor(Math.random() * 100)}`,
            pageSize: 10,
            cancelPerson: 'person name',
        }
    }

    pushTest(messageTest, 'Call', index)
}

0 个答案:

没有答案