public ResponseEntity findByContens(Integer page, Integer size, String[] split) {
MultiSearchRequestBuilder multiSearchRequestBuilder = client.prepareMultiSearch();
for (String key : split) {
SearchRequestBuilder builder = client.prepareSearch()
.setQuery(QueryBuilders.matchQuery("attachment.content", key))
.highlighter(new HighlightBuilder().preTags("<strong>").postTags("</strong>").field("attachment.content"))
.setFrom(page).setSize(size);
multiSearchRequestBuilder.add(builder);
}
MultiSearchResponse multiSearchResponse = multiSearchRequestBuilder.get();
return ResponseEntity.ok(multiSearchResponse);}
导致此异常:
2018-01-13 18:12:59.287 WARN 49204 --- [nio-8080-exec-2] .wsmsDefaultHandlerExceptionResolver:由Handler执行导致的已解决异常:org.springframework.http.converter.HttpMessageNotWritableException:无法写内容:没有找到类org.elasticsearch.common.text.Text的序列化程序,也没有发现创建BeanSerializer的属性(为了避免异常,禁用SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过引用链:org.elasticsearch.action.search.MultiSearchResponse [“响应 “] - &GT; org.elasticsearch.action.search.MultiSearchResponse $项目[” 响应 “] - &GT; org.elasticsearch.action.search.SearchResponse [” 命中“] - GT; org.elasticsearch.search.SearchHits [ “命中”] - GT; org.elasticsearch.search.SearchHit [ “highlightFields”] - &GT; java.util.Collections中$ SingletonMap [ “attachment.content”] - &GT; org.elasticsearch.search.fetch.subphase.highlight .HighlightField [ “片段”]);嵌套异常是com.fasterxml.jackson.databind.JsonMappingException:没有为类org.elasticsearch.common.text.Text找到序列化器,也没有发现创建BeanSerializer的属性(为了避免异常,禁用SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过引用链:org) .elasticsearch.action.search.MultiSearchResponse [ “反应”] - &GT; org.elasticsearch.action.search.MultiSearchResponse $项目[ “响应”] - &GT; org.elasticsearch.action.search.SearchResponse [ “命中”] - &GT; org.elasticsearch.search.SearchHits [ “命中”] - GT; org.elasticsearch.search.SearchHit [ “highlightFields”] - &GT; java.util.Collections中$ SingletonMap [ “attachment.content”] - &GT;有机.elasticsearch.search.fetch.subphase.highlight.HighlightField [ “片段”])
如何解决此异常?
答案 0 :(得分:0)
没有为类org.elasticsearch.common.text.Text
找到序列化程序
狂野猜测(因为没有足够的信息可以确定):您正在使用Elasticsearch 5.x或6.x,其中分析的字段属于text
类型,但您的Spring Data版本不是3.0 (这是Elasticsearch 5.x的当前版本和要求)。
要么将Spring Data Elasticsearch更新为3.x,要么这是Spring Boot的传递依赖项,您必须使用(即将发布)版本2.0。