java格式的日期到三个独立的字段进入elasticsearch

eufgjt7s  于 2021-06-13  发布在  ElasticSearch
关注(0)|答案(0)|浏览(232)

我正在尝试将日期解析为ElasticSearch,以便在kibana中基于月份、“一年中的一周”和“一周中的一天”创建控件图表。
我使用以下调用创建了索引:

PUT periodically-active-users/

{
    "mappings": {
        "properties": {
            "userId": {
                "type": "integer"
            },
            "date_month": {
                "type": "date",
                "format": "MMMM"
            },
            "date_week": {
                "type": "date",
                "format": "w"
            },
            "date_day": {
                "type": "date",
                "format": "dd"
            }
        }
    }
}

我用java生成如下插入:

private static final String DATE_FORMATTER_MONTH = "MMMM";
private static final String DATE_FORMATTER_WEEK = "w";
private static final String DATE_FORMATTER_DAY = "dd";

String date_month = LocalDate.now().format(DateTimeFormatter.ofPattern(DATE_FORMATTER_MONTH));
String date_week = LocalDate.now().format(DateTimeFormatter.ofPattern(DATE_FORMATTER_WEEK));
String date_day = LocalDate.now().format(DateTimeFormatter.ofPattern(DATE_FORMATTER_DAY));

MonthlyActiveUsers monthlyActiveUsers = new MonthlyActiveUsers(1, date_month, date_week, date_day);

获取send的monthlyactiveusers模型类:

@AllArgsConstructor
@NoArgsConstructor
@Getter
public class MonthlyActiveUsers {
    int userId;
    String date_month;
    String date_week;
    String date_day;
}

将对象发送到elastic search时,会出现以下解析异常:

400 Bad Request: [{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse field [date_month] of type [date] in document with id '1'. Preview of field's value: 'december'"}],"type":"mapper_p... (580 bytes)

先谢谢你。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题