私のマッピング:
{
"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 . それを取り除く方法はありますか?