热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ElasticSearch返回的hits里面获取不到数据

问题描述想要获取搜索结果中hits的数据,遍历his[]的时候发现为空。不知道是什么原因,es版本6.4.3,client版本6.4.3使用postman能获取

问题描述

想要获取搜索结果中hits的数据,遍历his[]的时候发现为空。不知道是什么原因,es版本6.4.3,client版本6.4.3
使用postman能获取数据。使用restclient,控制台显示如下:但是hits[] 中无内容。
总记录数:3
{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":3,"max_score":4.0247,"hits":[]}}
总记录数:3
{"took":5,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":3,"max_score":4.0247,"hits":[]}}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 searchText = "安装出错 pass";

        SearchRequest searchRequest = new SearchRequest(INDEX_NAME);

        searchRequest.types(INDEX_TYPE);

        SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();

        sourceBuilder.query(QueryBuilders.multiMatchQuery(searchText,"title","text"));

        sourceBuilder.from(PAGE_STAER);

        sourceBuilder.from(PAGE_SIZE);

        sourceBuilder.sort(new ScoreSortBuilder().order(SortOrder.DESC));

        searchRequest.source(sourceBuilder);



        try {

            SearchResponse searchRespOnse= client.search(searchRequest, RequestOptions.DEFAULT);

            SearchHits hits = searchResponse.getHits();

            SearchHit[] searchHits = hits.getHits();

            List tempEntityList = new ArrayList<>();

            for(SearchHit hit : searchHits){

                float score = hit.getScore();

                Map sourceAsMap = hit.getSourceAsMap();

                EsSearchDocResponseMessage tempEntity = new EsSearchDocResponseMessage();

                tempEntity.setScore(score);

                tempEntity.setText((String)sourceAsMap.get("text"));

                tempEntity.setArticleId((String)sourceAsMap.get("articleId"));

            }



   



推荐阅读
author-avatar
xsf9507
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有