Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

922
Visualizações
How to fix the error "failed to parse date field " in Elasticsearch

I tried to do a query in Elasticsearch via python. I want to get all values in the last one hour from now. For this I wrote this script:

import time
from elasticsearch import Elasticsearch
from datetime import datetime, timedelta

es = Elasticsearch()
index = "standalone"

filename = "2017-12-22V2.csv"

Timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
one_hour_from_now = datetime.now() - timedelta(hours=1)
one_hour_from_now = one_hour_from_now.strftime('%Y-%m-%d %H:%M:%S')


query = {"query":{"bool":{"must":{"range":{"Time":{"gt":one_hour_from_now,"lt":Timestamp}}},"must_not":[],"should":[]}},"from":0,"size":10,"sort":[],"aggs":{}}


ret = es.search(index, body=query)
print("ret", ret)

When I execute it I get this error:

 es.search exception:  TransportError(400, 'search_phase_execution_exception', 'failed to parse date field [2018-02-12 15:50:26] with format [strict_date_optional_time||epoch_millis]')

This is the structure of my ES index: Elasticsearch structure

Can someone help me please

Thank you

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

From the documentation it seems that you have fail the format date. According to your screenshot, your data is in this format:

yyyy-MM-dd'T'HH:mm:ss

According to the documentation this format is

date_hour_minute_second or strict_date_hour_minute_second

With datetime library in python you have shaped your date format in this way:

yyyy-MM-dd HH:mm:ss

Try to convert in the range query the strict_date_optional_time - the default date format in es, used in your date field according to the structure of your es index - with the format clause and cast it with the value yyyy-MM-dd HH:mm:ss

or change you line code:

one_hour_from_now = one_hour_from_now.strftime('%Y-%m-%d %H:%M:%S')

in

one_hour_from_now = one_hour_from_now.strftime("%Y-%m-%d"'T'"%H:%M:%S")

and don't specify a format in the query or specify the correct one

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda