我正在使用 ES 7.2。下面是来自 ES 的示例查询结果。它有两个字段 STATUS 和 SERVICE_ID:
{{
"took" : 4,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 106,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "myindex",
"_type" : "_doc",
"_id" : "ENXDrWsBF759w7WDGxK4",
"_score" : 1.0,
"_source" : {
"STATUS" : "10",
"SERVICE_ID" : "916"
}
},
{
"_index" : "myindex",
"_type" : "_doc",
"_id" : "EdXDrWsBF759w7WDGxK4",
"_score" : 1.0,
"_source" : {
"STATUS" : "10",
"SERVICE_ID" : "916"
}
}
]
}
}
我想将它映射到下面的 Java Bean“MyBean”:
public class MyBean {
String SERVICE_ID;
String STATUS;
public String getSERVICE_ID() {
return SERVICE_ID;
}
public void setSERVICE_ID(String sERVICE_ID) {
SERVICE_ID = sERVICE_ID;
}
public String getSTATUS() {
return STATUS;
}
public void setSTATUS(String sTATUS) {
STATUS = sTATUS;
}
}
我已经使用 ObjectMapper 的 jackson 库尝试了下面的映射,但它有以下异常:
try {
SearchResponse searchResponse1 = client.search(searchRequest, RequestOptions.DEFAULT);
ObjectMapper mapper = new ObjectMapper();
java.util.List<MyBean> lst = new ArrayList<MyBean>();
for(SearchHit hit : searchResponse1.getHits().getHits()) {
//here below, i have the exception
MyBean s = mapper.readValue(hit.getSourceAsString(), MyBean.class);
lst.add(s);
}
以下是例外情况:
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "STATUS" (class MyBean), not marked as ignorable (2 known properties: "status", "service_ID")
at [Source: (String)"{"STATUS":"11"}"; line: 1, column: 12] (through reference chain: MyBean["STATUS"])
你有什么主意吗?
慕姐4208626
相关分类