我有一个java.time.Instant
创建数据字段的实体:
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
public class Item {
private String id;
private String url;
private Instant createdDate;
}
Run Code Online (Sandbox Code Playgroud)
我com.fasterxml.jackson.databind.ObjectMapper
用来将项目保存为Elasticsearch作为JSON:
bulkRequestBody.append(objectMapper.writeValueAsString(item));
Run Code Online (Sandbox Code Playgroud)
ObjectMapper
将此字段序列化为对象:
"createdDate": {
"epochSecond": 1502643595,
"nano": 466000000
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试注释,@JsonFormat(shape = JsonFormat.Shape.STRING)
但它对我不起作用.
我的问题是如何将此字段序列化为2010-05-30 22:15:52
字符串?
我正在使用 Elasticsearch 5.5 并有一个具有此类映射的索引:
{
"my_index": {
"mappings": {
"my_type": {
"properties": {
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"my_array": {
"properties": {
"array": {
"type": "float"
},
"length": {
"type": "long"
}
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想按标题搜索并按数组中的第一个值排序。另外,如果将第一个值设置为该字段,那就太好了_score
。所以,我准备了这样的请求:
GET my_index/my_type/_search
{
"query": {
"term": {
"title.keyword": "Shorts"
}
},
"sort" : {
"_script" : {
"type" : "number",
"script" : {
"lang": "painless",
"inline": "doc['my_array.array'][0]"
}, …
Run Code Online (Sandbox Code Playgroud) 在任何应用程序中,春季启动是否有任何方法可以从请求中获取标头?一些静态的东西会很棒.
请注意,@RequestHeader
这对我不起作用,因为我需要在服务层上使用此值.