Java Code Examples for org.elasticsearch.search.SearchHits#forEach()
The following examples show how to use
org.elasticsearch.search.SearchHits#forEach() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchBuilder.java From microservices-platform with Apache License 2.0 | 6 votes |
/** * 返回JSON列表数据 */ private List<JSONObject> getList(SearchHits searchHits) { List<JSONObject> list = new ArrayList<>(); if (searchHits != null) { searchHits.forEach(item -> { JSONObject jsonObject = JSON.parseObject(item.getSourceAsString()); jsonObject.put("id", item.getId()); Map<String, HighlightField> highlightFields = item.getHighlightFields(); if (highlightFields != null) { populateHighLightedFields(jsonObject, highlightFields); } list.add(jsonObject); }); } return list; }
Example 2
Source File: SpiderInfoDAO.java From Gather-Platform with GNU General Public License v3.0 | 5 votes |
private List<SpiderInfo> warpHits2List(SearchHits hits) { List<SpiderInfo> spiderInfoList = Lists.newLinkedList(); hits.forEach(searchHitFields -> { spiderInfoList.add(warpHits2Info(searchHitFields)); }); return spiderInfoList; }
Example 3
Source File: CommonWebpageDAO.java From Gather-Platform with GNU General Public License v3.0 | 5 votes |
private List<Webpage> warpHits2List(SearchHits hits) { List<Webpage> webpageList = Lists.newLinkedList(); hits.forEach(searchHitFields -> { webpageList.add(warpHits2Info(searchHitFields)); }); return webpageList; }
Example 4
Source File: SpiderInfoDAO.java From spider with GNU General Public License v3.0 | 5 votes |
private List<SpiderInfo> warpHits2List(SearchHits hits) { List<SpiderInfo> spiderInfoList = Lists.newLinkedList(); hits.forEach(searchHitFields -> { spiderInfoList.add(warpHits2Info(searchHitFields)); }); return spiderInfoList; }
Example 5
Source File: CommonWebpageDAO.java From spider with GNU General Public License v3.0 | 5 votes |
private List<Webpage> warpHits2List(SearchHits hits) { List<Webpage> webpageList = Lists.newLinkedList(); hits.forEach(searchHitFields -> { webpageList.add(warpHits2Info(searchHitFields)); }); return webpageList; }
Example 6
Source File: EsAbstractBehavior.java From fess with Apache License 2.0 | 4 votes |
@Override protected <RESULT extends ENTITY> List<RESULT> delegateSelectList(final ConditionBean cb, final Class<? extends RESULT> entityType) { // #pending check response final SearchRequestBuilder builder = client.prepareSearch(asEsIndex()); final int from; final int size; if (cb.isFetchScopeEffective()) { from = cb.getPageStartIndex(); size = cb.getFetchSize(); } else { from = 0; size = 10; } builder.setFrom(from); builder.setSize(size); final EsAbstractConditionBean esCb = (EsAbstractConditionBean) cb; if (esCb.getPreference() != null) { builder.setPreference(esCb.getPreference()); } esCb.request().build(builder); final SearchResponse response = esCb.build(builder).execute().actionGet(searchTimeout); final EsPagingResultBean<RESULT> list = new EsPagingResultBean<>(builder); final SearchHits searchHits = getSearchHits(response); searchHits.forEach(hit -> { final Map<String, Object> source = hit.getSourceAsMap(); final RESULT entity = createEntity(source, entityType); final DocMeta docMeta = ((EsAbstractEntity) entity).asDocMeta(); docMeta.id(hit.getId()); docMeta.version(hit.getVersion()); docMeta.seqNo(hit.getSeqNo()); docMeta.primaryTerm(hit.getPrimaryTerm()); list.add(entity); }); list.setPageSize(size); list.setAllRecordCount((int) searchHits.getTotalHits().value); list.setCurrentPageNumber(cb.getFetchPageNumber()); list.setTook(response.getTook().getMillis()); list.setTotalShards(response.getTotalShards()); list.setSuccessfulShards(response.getSuccessfulShards()); list.setFailedShards(response.getFailedShards()); list.setTotalHits(searchHits.getTotalHits()); list.setAggregation(response.getAggregations()); // #pending others return list; }
Example 7
Source File: EsAbstractBehavior.java From fess with Apache License 2.0 | 4 votes |
@Override protected <RESULT extends ENTITY> List<RESULT> delegateSelectList(final ConditionBean cb, final Class<? extends RESULT> entityType) { // #pending check response final SearchRequestBuilder builder = client.prepareSearch(asEsIndex()); final int from; final int size; if (cb.isFetchScopeEffective()) { from = cb.getPageStartIndex(); size = cb.getFetchSize(); } else { from = 0; size = 10; } builder.setFrom(from); builder.setSize(size); final EsAbstractConditionBean esCb = (EsAbstractConditionBean) cb; if (esCb.getPreference() != null) { builder.setPreference(esCb.getPreference()); } esCb.request().build(builder); final SearchResponse response = esCb.build(builder).execute().actionGet(searchTimeout); final EsPagingResultBean<RESULT> list = new EsPagingResultBean<>(builder); final SearchHits searchHits = getSearchHits(response); searchHits.forEach(hit -> { final Map<String, Object> source = hit.getSourceAsMap(); final RESULT entity = createEntity(source, entityType); final DocMeta docMeta = ((EsAbstractEntity) entity).asDocMeta(); docMeta.id(hit.getId()); docMeta.version(hit.getVersion()); docMeta.seqNo(hit.getSeqNo()); docMeta.primaryTerm(hit.getPrimaryTerm()); list.add(entity); }); list.setPageSize(size); list.setAllRecordCount((int) searchHits.getTotalHits().value); list.setCurrentPageNumber(cb.getFetchPageNumber()); list.setTook(response.getTook().getMillis()); list.setTotalShards(response.getTotalShards()); list.setSuccessfulShards(response.getSuccessfulShards()); list.setFailedShards(response.getFailedShards()); list.setTotalHits(searchHits.getTotalHits()); list.setAggregation(response.getAggregations()); // #pending others return list; }
Example 8
Source File: EsAbstractBehavior.java From fess with Apache License 2.0 | 4 votes |
@Override protected <RESULT extends ENTITY> List<RESULT> delegateSelectList(final ConditionBean cb, final Class<? extends RESULT> entityType) { // #pending check response final SearchRequestBuilder builder = client.prepareSearch(asEsIndex()); final int from; final int size; if (cb.isFetchScopeEffective()) { from = cb.getPageStartIndex(); size = cb.getFetchSize(); } else { from = 0; size = 10; } builder.setFrom(from); builder.setSize(size); final EsAbstractConditionBean esCb = (EsAbstractConditionBean) cb; if (esCb.getPreference() != null) { builder.setPreference(esCb.getPreference()); } esCb.request().build(builder); final SearchResponse response = esCb.build(builder).execute().actionGet(searchTimeout); final EsPagingResultBean<RESULT> list = new EsPagingResultBean<>(builder); final SearchHits searchHits = getSearchHits(response); searchHits.forEach(hit -> { final Map<String, Object> source = hit.getSourceAsMap(); final RESULT entity = createEntity(source, entityType); final DocMeta docMeta = ((EsAbstractEntity) entity).asDocMeta(); docMeta.id(hit.getId()); docMeta.version(hit.getVersion()); docMeta.seqNo(hit.getSeqNo()); docMeta.primaryTerm(hit.getPrimaryTerm()); list.add(entity); }); list.setPageSize(size); list.setAllRecordCount((int) searchHits.getTotalHits().value); list.setCurrentPageNumber(cb.getFetchPageNumber()); list.setTook(response.getTook().getMillis()); list.setTotalShards(response.getTotalShards()); list.setSuccessfulShards(response.getSuccessfulShards()); list.setFailedShards(response.getFailedShards()); list.setTotalHits(searchHits.getTotalHits()); list.setAggregation(response.getAggregations()); // #pending others return list; }
Example 9
Source File: CamelSinkElasticSearchITCase.java From camel-kafka-connector with Apache License 2.0 | 3 votes |
public void runTest(ConnectorPropertyFactory propertyFactory) throws ExecutionException, InterruptedException { propertyFactory.log(); getKafkaConnectService().initializeConnector(propertyFactory); CountDownLatch latch = new CountDownLatch(1); ExecutorService service = Executors.newCachedThreadPool(); service.submit(() -> putRecords(latch)); if (!latch.await(30, TimeUnit.SECONDS)) { fail("Timed out wait for data to be added to the Kafka cluster"); } LOG.debug("Waiting for indices"); client.waitForIndex(); LOG.debug("Waiting for data"); client.waitForData(expect); SearchHits hits = client.getData(); assertNotNull(hits); hits.forEach(this::verifyHit); assertEquals(expect, received, "Did not receive the same amount of messages sent"); LOG.debug("Created the consumer ... About to receive messages"); }