初始化索引模板Elasticsearch一次

时间:2018-03-15 20:54:57

标签: node.js elasticsearch elasticsearch-6

如何在elasticsearch中初始化索引模板,而不是为每个put请求调用。我使用弹性js 6.2。并且可以指示一次索引模板吗?我使用putTemplate API,client.index API来定义设置,并在创建索引之前进行映射。现在,当putTemplate调用每个请求时。怎么避免呢?

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

        const templateSettings = {
            'index_patterns' : ['*'],
            order : 0,
            settings : {'number_of_shards' : 1},
            mappings : {
                [type] : {
                    'numeric_detection': true,
                    _source : {enabled : true},
                },
            },
        }

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

        await client.index({
            index: type.toLowerCase(),
            type,
            body: message,
        },
        (error, response) => {
            logger.silly('Pushing of data completed', response)

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

0 个答案:

没有答案