我的映射:
{
"field": {
"dynamic_templates": [{
"notanalyzed": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}],
"properties": {
"createdOn": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
},
"lastUpdatedOn": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
}
}
}
}
我的课程:
package be.smartask.core.api.data;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author Glenn Van Schil
* Created on 19/04/2016
*/
public class AbstractData {
private final static SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private String id;
private String createdOn;
private String lastUpdatedOn;
public AbstractData() {
}
public AbstractData(Date createdOn, String id, Date lastUpdatedOn) {
this.createdOn = SIMPLE_DATE_FORMAT.format(createdOn);
this.id = id;
this.lastUpdatedOn = SIMPLE_DATE_FORMAT.format(lastUpdatedOn);
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Date getCreatedOn() {
try {
return SIMPLE_DATE_FORMAT.parse(createdOn);
} catch (ParseException e) {
return null;
}
}
public void setCreatedOn(Date createdOn) {
this.createdOn = SIMPLE_DATE_FORMAT.format(createdOn);
}
public Date getLastUpdatedOn() {
try {
return SIMPLE_DATE_FORMAT.parse(lastUpdatedOn);
} catch (ParseException e) {
return null;
}
}
public void setLastUpdatedOn(Date lastUpdatedOn) {
this.lastUpdatedOn = SIMPLE_DATE_FORMAT.format(lastUpdatedOn);
}
}
和
package be.smartask.data;
import be.smartask.core.api.data.AbstractData;
import java.util.Date;
/**
* @author Glenn Van Schil
* Created on 25/01/2016
*/
public class Field extends AbstractData {
private String name;
private FieldType fieldType;
private String unit;
private String userId;
private String projectId;
public Field() {
}
public Field(Date createdOn, String id, Date lastUpdatedOn, FieldType fieldType, String name, String projectId, String unit, String userId) {
super(createdOn, id, lastUpdatedOn);
this.fieldType = fieldType;
this.name = name;
this.projectId = projectId;
this.unit = unit;
this.userId = userId;
}
public FieldType getFieldType() {
return fieldType;
}
public void setFieldType(FieldType fieldType) {
this.fieldType = fieldType;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getProjectId() {
return projectId;
}
public void setProjectId(String projectId) {
this.projectId = projectId;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
}
当我尝试索引它时,我收到以下错误
java.lang.IllegalArgumentException:无效格式:“1461223048000”在“8000”处格式错误
当我从映射中删除格式时,它需要strict_date_optional_time || epoch_millis默认为格式,但我不希望这样。
我在这里做错了什么,我该如何解决?
更新 1
当我将映射更改为:
{
"field": {
"dynamic_templates": [{
"notanalyzed": {
"match": "*",
"match_mapping_type": "string",
"mapping": {
"type": "string",
"index": "not_analyzed"
}
}
}],
"properties": {
"createdOn": {
"type": "date",
"format": "strict_date_hour_minute_second || epoch_millis"
},
"lastUpdatedOn": {
"type": "date",
"format": "strict_date_hour_minute_second || epoch_millis"
}
}
}
}
我的班级要:
package be.smartask.core.api.data;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author Glenn Van Schil
* Created on 19/04/2016
*/
public class AbstractData {
private String id;
private Date createdOn;
private Date lastUpdatedOn;
public AbstractData() {
}
public AbstractData(Date createdOn, String id, Date lastUpdatedOn) {
this.createdOn = createdOn;
this.id = id;
this.lastUpdatedOn = lastUpdatedOn;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Date getCreatedOn() {
return createdOn;
}
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
public Date getLastUpdatedOn() {
return lastUpdatedOn;
}
public void setLastUpdatedOn(Date lastUpdatedOn) {
this.lastUpdatedOn = lastUpdatedOn;
}
}
它有效,但我仍然喜欢在没有||的情况下这样做 epoch_millis。有没有办法摆脱它?