0
私はES Jestを使用しています。私は検索して回答を得ることができます。しかし、Date
プロパティでシリアル化を行うと、シリアル化後にnull
という応答が得られます。Elasticsearch JEST日付シリアル化java
以下は、ESドキュメントのインデックスと検索結果のクラスです。
public class IndexDocument {
public long id;
@JsonSerialize(using = JsonDateSerializer.class)
public Date Date1;
@JsonSerialize(using = JsonDateSerializer.class)
public Date Date2;
}
私は日付のシリアル化のためのESから
public class JsonDateSerializer extends JsonSerializer<Date> {
private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss.SSSZ");
@Override
public void serialize(Date date, JsonGenerator gen, SerializerProvider provider)
throws IOException, JsonProcessingException {
String formattedDate = dateFormat.format(date);
gen.writeString(formattedDate);
}
}
レスポンスを次のコードを持っている:
"hits" : [{
"_index" : "myindex",
"_type" : "mytype",
"_id" : "3",
"_score" : 1.3294203,
"_source" : {
"Date1" : "2016-11-24T14:39:08.000Z",
"id" : 1,
"Date2" : "1900-01-01T00:00:00.000Z"
}
}
]
私のシリアル化コード:シリアル化した後、私はを得た
JestResult result = client.execute(search); // i can see the response here
response = result.getSourceAsObjectList(IndexDocument.class);
注:indexDocumentからdateプロパティを削除すると、シリアル化された応答が表示されますが、dateプロパティでは機能しません。何が悪かったのか?
私は上記の例を試していますが、うまくいきます。あなたのマッピングを投稿できますか?上記の例のインデックスを作成すると、Mineが自動生成されますが、別のものがある可能性があります。私はjackson 2.4.6を使用しています – alkis