如何解决动态日期模板的问题?

时间:2019-04-12 10:32:46

标签: datetime elasticsearch bulk

我对动态日期填字游戏有疑问

我正在使用ElasticSearch 6.2.4

我的步骤:

1)使用下一个设置创建索引:

PUT /test1
{
    "settings": {
        "index":{
            "number_of_shards" : 9,
            "number_of_replicas" : 0,
            "max_rescore_window" : 2000000000,
            "max_result_window" : 2000000000
        }
    },
    "mappings": {
        "files": {
            "properties": {
                "Дата добавления в БД": {
                    "type": "date"
                }
            },
            "numeric_detection": true,
            "dynamic_templates": [
                {
                    "integers": {
                        "match_mapping_type": "long",
                        "mapping": {
                            "type": "long"
                        }
                    }
                },
                {
                    "strings": {
                        "match_mapping_type": "string",
                        "mapping": {
                            "type": "keyword"
                        }
                    }
                },
                {
                    "dates": {
                        "match_mapping_type": "date",
                        "mapping": {
                            "format": "yyyy-MM-dd HH:mm:ss||yyyy/MM/dd HH:mm:ss||yyyyMMdd_HH:mm:ss",
                            "type": "date"
                        }
                    }
                }
            ]
        }
    }
}

2)尝试放入新记录(我只有一个)

POST /test1/files/_bulk
{"create":{"_index":"test1","_type":"files","_id":"0"}}
{"Дата добавления в БД":"2019/04/12 11:42:21"}

3)所以,我有下一个输出:

{
    "took": 1,
    "errors": true,
    "items": [
        {
            "create": {
                "_index": "test1",
                "_type": "files",
                "_id": "0",
                "status": 400,
                "error": {
                    "type": "mapper_parsing_exception",
                    "reason": "failed to parse [Дата добавления в БД]",
                    "caused_by": {
                        "type": "illegal_argument_exception",
                        "reason": "Invalid format: \"2019/04/12 11:42:21\" is malformed at \"/04/12 11:42:21\""
                    }
                }
            }
        }
    ]
}

我不明白我的错误在哪里?? 我试图在Google中找到有关此问题的一些信息,但是,我没有解决该问题的方法。也许,这个问题太愚蠢了,但我已经伤脑筋了。 拜托,帮帮我...

1 个答案:

答案 0 :(得分:0)

我无法完全理解,但是此选项有效:

{
    "settings": {
        "index":{
            "number_of_shards" : 9,
            "number_of_replicas" : 0,
            "max_rescore_window" : 2000000000,
            "max_result_window" : 2000000000
        }
    },
    "mappings": {
        "files": {
        "dynamic_date_formats": ["yyyy-MM-dd HH:mm:ss","yyyy/MM/dd HH:mm:ss", "yyyyMMdd_HH:mm:ss"],
            "numeric_detection": true,
            "date_detection": true,

            "dynamic_templates": [
                {
                    "integers": {
                        "match_mapping_type": "long",
                        "mapping": {
                            "type": "long"
                        }
                    }
                },
                {
                    "strings": {
                        "match_mapping_type": "string",
                        "mapping": {
                            "type": "keyword"
                        }
                    }
                }
            ]
        }
    }
}

链接到文档: https://www.elastic.co/guide/en/elasticsearch/reference/6.2/dynamic-field-mapping.html

感谢关注:)