如何在 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)
}
})