Requesterror 400, 'search_phase_execution_exception', 'failed to parse date field Django

Asked

Viewed 17 times

0

I’m having trouble executing the views that receive an Elasticsearch, searches between dates coming from the template and returns a csv!

views:

...
data_inicio_template = request.POST.get('data_inicio')
data_fim_template = request.POST.get('data_fim')

data_inicio = datetime.strptime(data_inicio_template, '%Y/%m/%d %H:%M')
data_fim = datetime.strptime(data_fim_template, '%Y/%m/%d %H:%M')

body={"query":{"bool":{"filter":[{"range":{"data_importacao_rnds":{"gte":data_inicio,"lte":data_fim}}}]}}}
results = elasticsearch.helpers.scan(es, query=body, index=index)
df = pd.DataFrame.from_dict([document['_source'] for document in results])

response = HttpResponse(content_type='text/csv')

response['Content-Disposition'] = 'attachment; filename=dados'

df.to_csv(response, index = False)

return response

Error in that line: df = pd.DataFrame.from_dict([document['_source'] for document in results])

HTML:

<input id="datetimepicker" type="text" class="form-control form-control-sm" name="data_inicio" required>
<input id="datetimepicker2" type="text" class="form-control form-control-sm" name="data_fim" required>
<script>
$(function () {
  $("#datetimepicker").datetimepicker();
});
$(function () {
  $("#datetimepicker2").datetimepicker();
});

Ex.A survey between 20 and 21 May 2021, returns:

Requesterror(400, 'search_phase_execution_exception', 'failed to parse date field [2021-05-20T11:23:00] with format [[yyyy-MM-dd HH:mm:ss]]: [failed to parse date field [2021-05-20T11:23:00] with format [[yyyy-MM-dd HH:mm:ss:ss]]]')

  • Have you checked if the date/time template is correct? In the error the string that comes has a T in the middle of the timestamp, and your template does not appear to have.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.