gpt4 book ai didi

elasticsearch - 在Elasticsearch中解析日期 “April 10th 2018, 07:32:45.987”

转载 作者:行者123 更新时间:2023-12-03 01:38:46 24 4
gpt4 key购买 nike

Heyo,我正在尝试使用Kibana创建索引模式,为此,我需要在Elasticsearch中解析日期“April 10th 2018,07:32:45.987”。我的问题是10以后的“th”。Elasticsearch文档使我指向了joda-time文档:http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html,但这并没有告诉我它如何忽略或解析这两个字符。到目前为止,我有:

PUT mynewindex
{
"mappings": {
"mytype" : {
"properties": {
"syslog-timestamp" : {
"type" : "date",
"format" : "MMM dd?? yyyy, HH:mm:ss.SSS"
}
}
}
}
}

用什么代替我的问号?

在Java中,它看起来像这样:
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class JodaTimeTest {


public JodaTimeTest() {
String timeString = "April 10th 2018, 07:32:45.987";
DateTimeFormatter formatter = DateTimeFormat.forPattern("MMM dd'th' yyyy, HH:mm:ss.SSS||MMM dd'nd' yyyy, HH:mm:ss.SSS||MMM dd'rd' yyyy, HH:mm:ss.SSS");
DateTime dt = formatter.parseDateTime(timeString);
}

public static void main(String[] args) {
new JodaTimeTest();
}
}

我尝试了给定的解决方案,但结果是:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid format: "April 10th 2018, 07:32:45.987" is too short
at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:945)
at JodaTimeTest.<init>(JodaTimeTest.java:11)
at JodaTimeTest.main(JodaTimeTest.java:15)

额外的信息:
GET myindex/_search
{
"query": {
"range" : {
"date" : {
"gt" : "now"
}
}
}
}

什么也不返回,并且
GET myindex/_search
{
"query": {
"range" : {
"date" : {
"lt" : "now"
}
}
}
}

也不会返回任何内容。

最佳答案

您需要这样做,并且还要用ndrd解释日期:

PUT mynewindex
{
"mappings": {
"mytype" : {
"properties": {
"syslog-timestamp" : {
"type" : "date",
"format" : "MMM dd'th' yyyy, HH:mm:ss.SSS||MMM dd'nd' yyyy, HH:mm:ss.SSS||MMM dd'rd' yyyy, HH:mm:ss.SSS"
}
}
}
}
}

关于elasticsearch - 在Elasticsearch中解析日期 “April 10th 2018, 07:32:45.987”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49812579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com