@Test @SuppressWarnings({ "unchecked" }) public void getTotalDistributionForIndexAndTypeWithMatchPhraseTest() throws Exception { final ElasticSearchRepository classUnderTest = PowerMockito.spy(new ElasticSearchRepository()); ReflectionTestUtils.setField(classUnderTest, "esUrl", "esUrl123"); mockStatic(Strings.class); mockStatic(PacHttpUtils.class); PowerMockito.when(Strings.isNullOrEmpty(anyString())).thenReturn(false); String response = "{\"count\":\"1234\", \"hits\":{\"total\":1000,\"max_score\":null,\"hits\":[{\"_index\":\"bank\",\"_type\":\"_doc\",\"_id\":\"0\",\"sort\":[0],\"_score\":null,\"_source\":{\"account_number\":0,\"balance\":16623,\"firstname\":\"Bradshaw\",\"lastname\":\"Mckenzie\",\"age\":29,\"gender\":\"F\",\"address\":\"244 Columbus Place\",\"employer\":\"Euron\",\"email\":\"bradshawmckenzie@euron.com\",\"city\":\"Hobucken\",\"state\":\"CO\"}}]},\"aggregations\":{\"accountid\":{\"buckets\":[{\"accountname\":{\"buckets\" :[{\"key\":\"key678\"}]},\"key\":\"key123\"},{\"accountname\":{\"buckets\" :[{\"key\":\"key566\"}]},\"key\":\"key455\"}]}}}"; PowerMockito.when(PacHttpUtils.doHttpPost(anyString(), anyString())).thenReturn(response); assertThat(classUnderTest.getTotalDistributionForIndexAndTypeWithMatchPhrase(eq("index"), eq("type"), anyMap(), anyMap(), anyObject(), anyString(), anyMap(), anyMap()), is(1234L)); }
@SuppressWarnings("unchecked") public long getTotalDistributionForIndexAndTypeWithMatchPhrase(String index, String type, Map<String, Object> mustFilter, Map<String, Object> mustNotFilter, HashMultimap<String, Object> shouldFilter, String searchText, Map<String, Object> mustTermsFilter, Map<String, List<String>> matchPhrasePrefix) throws Exception { String urlToQuery = buildCountURL(esUrl, index, type); Map<String, Object> requestBody = new HashMap<String, Object>(); Map<String, Object> matchFilters = Maps.newHashMap(); if (mustFilter == null) { matchFilters.put("match_all", new HashMap<String, String>()); } else { matchFilters.putAll(mustFilter); } if (null != mustFilter) { requestBody.put( QUERY, buildQuery(matchFilters, mustNotFilter, shouldFilter, searchText, mustTermsFilter, matchPhrasePrefix)); } else { requestBody.put(QUERY, matchFilters); } String responseDetails = null; Gson gson = new GsonBuilder().create(); try { String requestJson = gson.toJson(requestBody, Object.class); responseDetails = PacHttpUtils.doHttpPost(urlToQuery, requestJson); Map<String, Object> response = (Map<String, Object>) gson.fromJson( responseDetails, Object.class); return (long) (Double.parseDouble(response.get(COUNT).toString())); } catch (Exception e) { LOGGER.error(ERROR_RETRIEVING_INVENTORY_FROM_ES, e); throw e; } }
ElasticSearchRepository implements Constants { @SuppressWarnings("unchecked") public long getTotalDistributionForIndexAndTypeWithMatchPhrase(String index, String type, Map<String, Object> mustFilter, Map<String, Object> mustNotFilter, HashMultimap<String, Object> shouldFilter, String searchText, Map<String, Object> mustTermsFilter, Map<String, List<String>> matchPhrasePrefix) throws Exception { String urlToQuery = buildCountURL(esUrl, index, type); Map<String, Object> requestBody = new HashMap<String, Object>(); Map<String, Object> matchFilters = Maps.newHashMap(); if (mustFilter == null) { matchFilters.put("match_all", new HashMap<String, String>()); } else { matchFilters.putAll(mustFilter); } if (null != mustFilter) { requestBody.put( QUERY, buildQuery(matchFilters, mustNotFilter, shouldFilter, searchText, mustTermsFilter, matchPhrasePrefix)); } else { requestBody.put(QUERY, matchFilters); } String responseDetails = null; Gson gson = new GsonBuilder().create(); try { String requestJson = gson.toJson(requestBody, Object.class); responseDetails = PacHttpUtils.doHttpPost(urlToQuery, requestJson); Map<String, Object> response = (Map<String, Object>) gson.fromJson( responseDetails, Object.class); return (long) (Double.parseDouble(response.get(COUNT).toString())); } catch (Exception e) { LOGGER.error(ERROR_RETRIEVING_INVENTORY_FROM_ES, e); throw e; } } }
ElasticSearchRepository implements Constants { @SuppressWarnings("unchecked") public long getTotalDistributionForIndexAndTypeWithMatchPhrase(String index, String type, Map<String, Object> mustFilter, Map<String, Object> mustNotFilter, HashMultimap<String, Object> shouldFilter, String searchText, Map<String, Object> mustTermsFilter, Map<String, List<String>> matchPhrasePrefix) throws Exception { String urlToQuery = buildCountURL(esUrl, index, type); Map<String, Object> requestBody = new HashMap<String, Object>(); Map<String, Object> matchFilters = Maps.newHashMap(); if (mustFilter == null) { matchFilters.put("match_all", new HashMap<String, String>()); } else { matchFilters.putAll(mustFilter); } if (null != mustFilter) { requestBody.put( QUERY, buildQuery(matchFilters, mustNotFilter, shouldFilter, searchText, mustTermsFilter, matchPhrasePrefix)); } else { requestBody.put(QUERY, matchFilters); } String responseDetails = null; Gson gson = new GsonBuilder().create(); try { String requestJson = gson.toJson(requestBody, Object.class); responseDetails = PacHttpUtils.doHttpPost(urlToQuery, requestJson); Map<String, Object> response = (Map<String, Object>) gson.fromJson( responseDetails, Object.class); return (long) (Double.parseDouble(response.get(COUNT).toString())); } catch (Exception e) { LOGGER.error(ERROR_RETRIEVING_INVENTORY_FROM_ES, e); throw e; } }  }
ElasticSearchRepository implements Constants { @SuppressWarnings("unchecked") public long getTotalDistributionForIndexAndTypeWithMatchPhrase(String index, String type, Map<String, Object> mustFilter, Map<String, Object> mustNotFilter, HashMultimap<String, Object> shouldFilter, String searchText, Map<String, Object> mustTermsFilter, Map<String, List<String>> matchPhrasePrefix) throws Exception { String urlToQuery = buildCountURL(esUrl, index, type); Map<String, Object> requestBody = new HashMap<String, Object>(); Map<String, Object> matchFilters = Maps.newHashMap(); if (mustFilter == null) { matchFilters.put("match_all", new HashMap<String, String>()); } else { matchFilters.putAll(mustFilter); } if (null != mustFilter) { requestBody.put( QUERY, buildQuery(matchFilters, mustNotFilter, shouldFilter, searchText, mustTermsFilter, matchPhrasePrefix)); } else { requestBody.put(QUERY, matchFilters); } String responseDetails = null; Gson gson = new GsonBuilder().create(); try { String requestJson = gson.toJson(requestBody, Object.class); responseDetails = PacHttpUtils.doHttpPost(urlToQuery, requestJson); Map<String, Object> response = (Map<String, Object>) gson.fromJson( responseDetails, Object.class); return (long) (Double.parseDouble(response.get(COUNT).toString())); } catch (Exception e) { LOGGER.error(ERROR_RETRIEVING_INVENTORY_FROM_ES, e); throw e; } }  @SuppressWarnings("unchecked") @Deprecated List<Map<String, Object>> getDataFromES(String dataSource, String targetType, Map<String, Object> mustFilter,
			final Map<String, Object> mustNotFilter, final HashMultimap<String, Object> shouldFilter,
			List<String> fields, Map<String, Object> mustTermsFilter); @SuppressWarnings("unchecked") List<Map<String, Object>> getSortedDataFromES(String dataSource, String targetType,
			Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
			final HashMultimap<String, Object> shouldFilter, List<String> fields, Map<String, Object> mustTermsFilter,
			List<Map<String, Object>> sortFieldMapList); Map<String, Object> buildAggs(String distributionName, int size, String aggsName, Map<String, Object> nestedAggs); Map<String, Object> buildQuery(final Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
			final HashMultimap<String, Object> shouldFilter, final String searchText,
			final Map<String, Object> mustTermsFilter,Map<String, List<String>> matchPhrasePrefix); String buildScrollRequest(String scrollId, String esPageScrollTtl); String processResponseAndSendTheScrollBack(String responseDetails, List<Map<String, Object>> results); @SuppressWarnings("unchecked") long getTotalDocumentCountForIndexAndType(String index, String type, Map<String, Object> mustFilter,
			Map<String, Object> mustNotFilter, HashMultimap<String, Object> shouldFilter, String searchText,
			Map<String, Object> mustTermsFilter); Map<String, Long> getTotalDistributionForIndexAndType(String index, String type,
			Map<String, Object> mustFilter, Map<String, Object> mustNotFilter,
			HashMultimap<String, Object> shouldFilter, String aggsFilter, int size, Map<String, Object> mustTermsFilter); String buildAggsURL(String url, String index, String type); List<Map<String, Object>> getUtilizationByAssetGroup(String asseGroup); @Deprecated List<Map<String, Object>> getDataFromESBySize(String dataSource, String targetType,
			final Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
			final HashMultimap<String, Object> shouldFilter, List<String> fields, int from, int size, String searchText,
			final Map<String, Object> mustTermsFilter); List<Map<String, Object>> getSortedDataFromESBySize(String dataSource, String targetType,
			final Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
			final HashMultimap<String, Object> shouldFilter, List<String> fields, int from, int size, String searchText,
			final Map<String, Object> mustTermsFilter, List<Map<String, Object>> sortFieldMapList); @SuppressWarnings("unchecked") Boolean updatePartialDataToES(String dataSource, String targetType, String id, String routing, String parent,
			Map<String, Object> partialDocument); @SuppressWarnings("unchecked") Boolean saveExceptionDataToES(String dataSource, String routing, Map<String, Object> data); Map<String, Long> getTotalDistributionForIndexAndTypeBySize(String index, String type,
			Map<String, Object> mustFilter, Map<String, Object> mustNotFilter,
			HashMultimap<String, Object> shouldFilter, String aggsFilter, int size, int from, String searchText); Map<String, Long> getDateHistogramForIndexAndTypeByInterval(String index, String type,
			Map<String, Object> mustFilter, Map<String, Object> mustNotFilter,
			HashMultimap<String, Object> shouldFilter, String dateFieldName, String interval); Map<String, String> getAccountsByMultiAggs(String index, String type, Map<String, Object> filter,
			Map<String, Object> mustNotFilter, HashMultimap<String, Object> shouldFilter,
			Map<String, Object> aggsFilter, int size); List<LinkedHashMap<String, Object>> getDetailsFromESBySize(String dataSource, String targetType,
			final Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
			final HashMultimap<String, Object> shouldFilter, List<String> fields, int from, int size, String searchText,
			final Map<String, Object> mustTermsFilter); @SuppressWarnings("unchecked") @Deprecated List<Map<String, Object>> getDataFromESWithMustNotTermsFilter(String dataSource, String targetType,
			Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
			final HashMultimap<String, Object> shouldFilter, List<String> fields, Map<String, Object> mustTermsFilter,
			Map<String, Object> mustNotTermsFilter, Map<String, Object> mustNotWildCardFilter); @SuppressWarnings("unchecked") List<Map<String, Object>> getSortedDataFromESWithMustNotTermsFilter(String dataSource, String targetType,
			Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
			final HashMultimap<String, Object> shouldFilter, List<String> fields, Map<String, Object> mustTermsFilter,
			Map<String, Object> mustNotTermsFilter, Map<String, Object> mustNotWildCardFilter,
			List<Map<String, Object>> sortFieldMapList); long getTotalDocumentCountForIndexAndTypeWithMustNotTermsFilter(String index, String type,
			Map<String, Object> mustFilter, Map<String, Object> mustNotFilter,
			HashMultimap<String, Object> shouldFilter, String searchText, Map<String, Object> mustTermsFilter,
			Map<String, Object> mustNotTermsFilter, Map<String, Object> mustNotWildCardFilter); @SuppressWarnings("unchecked") long getTotalDistributionForIndexAndTypeWithMatchPhrase(String index, String type,
			Map<String, Object> mustFilter, Map<String, Object> mustNotFilter,
			HashMultimap<String, Object> shouldFilter, String searchText,
			Map<String, Object> mustTermsFilter,
			Map<String, List<String>> matchPhrasePrefix); String buildESURL(String url, String index, String type, int size, int from); Map<String, Object> getEnvAndTotalDistributionForIndexAndType(String index, String type,
			Map<String, Object> mustFilter, Map<String, Object> mustNotFilter,
			HashMultimap<String, Object> shouldFilter, String aggsFilter, Map<String, Object> nestedaggs, int size, Map<String, Object> mustTermsFilter); }
ElasticSearchRepository implements Constants { @SuppressWarnings("unchecked") public long getTotalDistributionForIndexAndTypeWithMatchPhrase(String index, String type, Map<String, Object> mustFilter, Map<String, Object> mustNotFilter, HashMultimap<String, Object> shouldFilter, String searchText, Map<String, Object> mustTermsFilter, Map<String, List<String>> matchPhrasePrefix) throws Exception { String urlToQuery = buildCountURL(esUrl, index, type); Map<String, Object> requestBody = new HashMap<String, Object>(); Map<String, Object> matchFilters = Maps.newHashMap(); if (mustFilter == null) { matchFilters.put("match_all", new HashMap<String, String>()); } else { matchFilters.putAll(mustFilter); } if (null != mustFilter) { requestBody.put( QUERY, buildQuery(matchFilters, mustNotFilter, shouldFilter, searchText, mustTermsFilter, matchPhrasePrefix)); } else { requestBody.put(QUERY, matchFilters); } String responseDetails = null; Gson gson = new GsonBuilder().create(); try { String requestJson = gson.toJson(requestBody, Object.class); responseDetails = PacHttpUtils.doHttpPost(urlToQuery, requestJson); Map<String, Object> response = (Map<String, Object>) gson.fromJson( responseDetails, Object.class); return (long) (Double.parseDouble(response.get(COUNT).toString())); } catch (Exception e) { LOGGER.error(ERROR_RETRIEVING_INVENTORY_FROM_ES, e); throw e; } }  @SuppressWarnings("unchecked") @Deprecated List<Map<String, Object>> getDataFromES(String dataSource, String targetType, Map<String, Object> mustFilter,
			final Map<String, Object> mustNotFilter, final HashMultimap<String, Object> shouldFilter,
			List<String> fields, Map<String, Object> mustTermsFilter); @SuppressWarnings("unchecked") List<Map<String, Object>> getSortedDataFromES(String dataSource, String targetType,
			Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
			final HashMultimap<String, Object> shouldFilter, List<String> fields, Map<String, Object> mustTermsFilter,
			List<Map<String, Object>> sortFieldMapList); Map<String, Object> buildAggs(String distributionName, int size, String aggsName, Map<String, Object> nestedAggs); Map<String, Object> buildQuery(final Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
			final HashMultimap<String, Object> shouldFilter, final String searchText,
			final Map<String, Object> mustTermsFilter,Map<String, List<String>> matchPhrasePrefix); String buildScrollRequest(String scrollId, String esPageScrollTtl); String processResponseAndSendTheScrollBack(String responseDetails, List<Map<String, Object>> results); @SuppressWarnings("unchecked") long getTotalDocumentCountForIndexAndType(String index, String type, Map<String, Object> mustFilter,
			Map<String, Object> mustNotFilter, HashMultimap<String, Object> shouldFilter, String searchText,
			Map<String, Object> mustTermsFilter); Map<String, Long> getTotalDistributionForIndexAndType(String index, String type,
			Map<String, Object> mustFilter, Map<String, Object> mustNotFilter,
			HashMultimap<String, Object> shouldFilter, String aggsFilter, int size, Map<String, Object> mustTermsFilter); String buildAggsURL(String url, String index, String type); List<Map<String, Object>> getUtilizationByAssetGroup(String asseGroup); @Deprecated List<Map<String, Object>> getDataFromESBySize(String dataSource, String targetType,
			final Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
			final HashMultimap<String, Object> shouldFilter, List<String> fields, int from, int size, String searchText,
			final Map<String, Object> mustTermsFilter); List<Map<String, Object>> getSortedDataFromESBySize(String dataSource, String targetType,
			final Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
			final HashMultimap<String, Object> shouldFilter, List<String> fields, int from, int size, String searchText,
			final Map<String, Object> mustTermsFilter, List<Map<String, Object>> sortFieldMapList); @SuppressWarnings("unchecked") Boolean updatePartialDataToES(String dataSource, String targetType, String id, String routing, String parent,
			Map<String, Object> partialDocument); @SuppressWarnings("unchecked") Boolean saveExceptionDataToES(String dataSource, String routing, Map<String, Object> data); Map<String, Long> getTotalDistributionForIndexAndTypeBySize(String index, String type,
			Map<String, Object> mustFilter, Map<String, Object> mustNotFilter,
			HashMultimap<String, Object> shouldFilter, String aggsFilter, int size, int from, String searchText); Map<String, Long> getDateHistogramForIndexAndTypeByInterval(String index, String type,
			Map<String, Object> mustFilter, Map<String, Object> mustNotFilter,
			HashMultimap<String, Object> shouldFilter, String dateFieldName, String interval); Map<String, String> getAccountsByMultiAggs(String index, String type, Map<String, Object> filter,
			Map<String, Object> mustNotFilter, HashMultimap<String, Object> shouldFilter,
			Map<String, Object> aggsFilter, int size); List<LinkedHashMap<String, Object>> getDetailsFromESBySize(String dataSource, String targetType,
			final Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
			final HashMultimap<String, Object> shouldFilter, List<String> fields, int from, int size, String searchText,
			final Map<String, Object> mustTermsFilter); @SuppressWarnings("unchecked") @Deprecated List<Map<String, Object>> getDataFromESWithMustNotTermsFilter(String dataSource, String targetType,
			Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
			final HashMultimap<String, Object> shouldFilter, List<String> fields, Map<String, Object> mustTermsFilter,
			Map<String, Object> mustNotTermsFilter, Map<String, Object> mustNotWildCardFilter); @SuppressWarnings("unchecked") List<Map<String, Object>> getSortedDataFromESWithMustNotTermsFilter(String dataSource, String targetType,
			Map<String, Object> mustFilter, final Map<String, Object> mustNotFilter,
			final HashMultimap<String, Object> shouldFilter, List<String> fields, Map<String, Object> mustTermsFilter,
			Map<String, Object> mustNotTermsFilter, Map<String, Object> mustNotWildCardFilter,
			List<Map<String, Object>> sortFieldMapList); long getTotalDocumentCountForIndexAndTypeWithMustNotTermsFilter(String index, String type,
			Map<String, Object> mustFilter, Map<String, Object> mustNotFilter,
			HashMultimap<String, Object> shouldFilter, String searchText, Map<String, Object> mustTermsFilter,
			Map<String, Object> mustNotTermsFilter, Map<String, Object> mustNotWildCardFilter); @SuppressWarnings("unchecked") long getTotalDistributionForIndexAndTypeWithMatchPhrase(String index, String type,
			Map<String, Object> mustFilter, Map<String, Object> mustNotFilter,
			HashMultimap<String, Object> shouldFilter, String searchText,
			Map<String, Object> mustTermsFilter,
			Map<String, List<String>> matchPhrasePrefix); String buildESURL(String url, String index, String type, int size, int from); Map<String, Object> getEnvAndTotalDistributionForIndexAndType(String index, String type,
			Map<String, Object> mustFilter, Map<String, Object> mustNotFilter,
			HashMultimap<String, Object> shouldFilter, String aggsFilter, Map<String, Object> nestedaggs, int size, Map<String, Object> mustTermsFilter);  }