I'm trying to index a lot of records but I'm facing some troubles when index publish_up
field. I mapped that field as date and format by default but
I get this error:
Error: 400 {"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse field [publish_up] of type [date]"}],"type":"mapper_parsing_exception","reason":"failed to parse field [publish_up] of type [date]","caused_by":{"type":"illegal_argument_exception","reason":"Invalid format: \"2015-02-11 00:00:00\" is malformed at \" 00:00:00\""}},"status":400}
This is how I configure index:
$params = [
'index' => 'attachments',
'body' => [
'settings' => [
'number_of_shards' => 1,
'analysis' => [
'analyzer' => [
'custom_analizer_texto_sub' => [
'type' => 'custom',
'tokenizer' => 'keyword',
'filter' => ['lowercase']
]
]
]
],
'mappings' => [
'article' => [
'_source' => [
'enabled' => true
],
'properties' => [
'iddoc' => [ 'type' => 'integer'],
'publish_up' => [ 'type' => 'date'],//, 'format' => 'YYYY-mm-dd HH:mm:ss'], //Y/m/d H:i:s
'textofull' => [ 'type' => 'keyword']
]
]
]
]
];
$response = $client->indices()->create($params);
And index code (here I get the error):
$params = [
'index' => 'attachments',
'type' => 'documentos',
'id' => $datos->id,
'body' => [
'iddoc' => $datos->id,
'publish_up' => $datos->publish_up,
'textofull' => $datos->fulltext
]
];
$response = $client->index($params);
NOTE: $datos->publish_up
has this dateformat 2015-02-11 00:00:00
. I checked Documentation but I can't solve my problem.
Since your date format is not standard ISO8601 (missing the T
between the date and the time), you need to add a format in your mapping. You did, but the pattern was wrong, as you used YYYY
for years instead of yyyy
and mm
for months instead of MM
. Try like this:
'publish_up' => [ 'type' => 'date', 'format' => 'yyyy-MM-dd HH:mm:ss'],
^ ^
| |
change these
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With