Erro de tempo limite do índice em massa de pesquisa elástica! Erro: tempo limite da solicitação após 30000ms
Recentemente, desejo rolar os dados antigos do índice para novos índices mensais. Os dados armazenados começam em 2015/07 até agora. e são quase 30.000 registros por mês. Segue orolagem emassa métodos fornecidos em2.2 API, Finalizo o código da seguinte maneira.
Arquivomain.coffee
logger = require 'graceful-logger'
elasticsearch = require 'elasticsearch'
setMonthlyIndices = require './es-test-promise'
client = new elasticsearch.Client
host:
host: 'localhost'
port: 9200
protocol: 'http'
setMonthlyIndices client, 'es_test_messages', 'talk_messages_v2', 'messages', 2015, 6
Arquivoes-test-promise.coffee
logger = require 'graceful-logger'
elasticsearch = require 'elasticsearch'
config = require 'config'
setIndice = (client, prefix, index, type, year, month) ->
allDocs = []
count = 0
prevYear = year + ''
# with leading '0' for month less than 10
prevMonth = ("0" + month).slice(-2)
nextDate = new Date(year, month)
nextYear = nextDate.getFullYear().toString()
nextMonth = ("0" + (nextDate.getMonth()+1)).slice(-2)
minDate = "#{prevYear}-#{prevMonth}-01"
maxDate = "#{nextYear}-#{nextMonth}-01"
indice_name = "#{prefix}_#{prevYear}_#{prevMonth}"
q =
filtered:
filter:
range:
createdAt:
gte: minDate
lt: maxDate
format: "yyyy-MM-dd"
client.search
index: index
type: type
scroll: '1m'
body:
query: q
sort: ['_doc']
size: 1000
, callback = (err, response) ->
console.log "indice_name 1", indice_name
return logger.err err.stack if err
return unless response.hits?.total
allDocs = []
response.hits.hits.forEach (hit)->
action =
index:
_id: hit._id
allDocs.push(action)
allDocs.push(hit._source)
count = count + allDocs.length
client.bulk
index: indice_name
type: type
body: allDocs
, (err, resp) ->
console.log "indice_name 2", indice_name
return logger.err err.stack if err
if response.hits.total *2 != count
client.scroll
scrollId: response._scroll_id
scroll: '1m'
, callback
else
logger.info "Finish indicing #{indice_name}"
setMonthlyIndices = (client, prefix, index, type, year, month) ->
current = new Date()
currentYear = current.getFullYear()
currentMonth = current.getMonth() + 1
processYear = year or currentYear
processMonth = month or 0
processDate = new Date(processYear, processMonth)
currentDate = new Date(currentYear, currentMonth)
processDate = new Date(2015, 6)
currentDate = new Date(2015, 9)
while processDate <= currentDate
year = processDate.getFullYear()
month = processDate.getMonth() + 1
setIndice(client, prefix, index, type, year, month)
processDate.setMonth(processDate.getMonth() + 1)
module.exports = setMonthlyIndices
Gostaria de saber se é devido a abrir muitas solicitações de clientes, porque no arquivoes-test-promise.coffee, todas essas solicitações de pesquisa estão sendo executadas simultaneamente. Isso é apenas um palpite, e então eu também tentei implementar compromessa para garantir que a solicitação possa ser executada uma a uma. Finalmente, eu não consigo entender e desistir.
Você tem alguma sugestão, acho que devem ser os problemas de origem, mas não sei onde verificar ...