无法解析 [date] 类型的字段 [datefield]

Ren*_*mon 5 php elasticsearch

我正在尝试索引很多记录,但是在索引publish_up字段时遇到了一些麻烦。默认情况下,我将该字段映射为日期和格式,但出现此错误:

错误:400 {"error":{"root_cause":[{"type":"mapper_parsing_exception","re​​ason":"未能解析 [date]"} 类型的字段 [publish_up]],"type":"mapper_parsing_exception ","re​​ason":"无法解析 [date] 类型的字段 [publish_up]","caused_by":{"type":"illegal_argument_exception","re​​ason":"无效格式:\"2015-02-11 00 :00:00\" 格式错误于 \" 00:00:00\""}},"status":400}

这是我配置索引的方式:

$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);
Run Code Online (Sandbox Code Playgroud)

和索引代码(在这里我得到错误):

    $params = [
        'index' => 'attachments',
        'type' => 'documentos',
        'id' => $datos->id,
        'body' => [
            'iddoc' => $datos->id,
            'publish_up' => $datos->publish_up,
            'textofull' => $datos->fulltext
        ]
    ];
    $response = $client->index($params);
Run Code Online (Sandbox Code Playgroud)

注意: $datos->publish_up有这个 dateformat 2015-02-11 00:00:00。我检查了文档,但无法解决我的问题。

Val*_*Val 6

由于您的日期格式不是标准 ISO8601(缺少T日期和时间之间),因此您需要在映射中添加格式。你这样做了,但模式是错误的,因为你用了YYYYyears而不是fors yyyymmformonths而不是MM。尝试这样:

                'publish_up' => [ 'type' => 'date', 'format' => 'yyyy-MM-dd HH:mm:ss'],
                                                                   ^  ^
                                                                   |  |
                                                               change these
Run Code Online (Sandbox Code Playgroud)