@Test public void testHttpParseWithNoDocsReturned() { System.setProperty(ConfigurationConstants.PROPNAME_ELASTIC_SEARCH_HTTP_HOSTS, "http: Configuration configuration = new SystemPropertiesConfiguration(); HttpElasticSearchClientFactory factory = new AHCHttpElasticSearchClientFactory(configuration); repository = new ElasticSearchRelatedItemHttpGetRepository(configuration,factory); Map<String,String> map = repository.getRelatedItemDocument(new String[]{"5","6"}); assertEquals("Should have parsed to items",3,map.size()); assertEquals("Document id 5 contains no source", "{}", map.get("5")); assertEquals("Document id 6 contains no source","{}",map.get("6")); }
@Override public Map<String, String> getRelatedItemDocument(String[] ids) { Map<String,String> getResults = RelatedItemNoopGetRepository.getEmptyResults(ids); log.debug("MGET request to execute {} get request", ids.length); String arrayString = createArray(ids); String jsonStart = "{\"ids\":"; StringBuilder b = new StringBuilder(arrayString.length()+jsonStart.length()+1); b.append(jsonStart).append(arrayString).append('}'); String searchJson = b.toString(); log.debug("MGET request json is {}",searchJson); SearchResultEventWithSearchRequestKey[] results; HttpResult sr; long startNanos = System.nanoTime(); sr = elasticClient.executeSearch(HttpMethod.POST,url,searchJson); HttpSearchExecutionStatus searchRequestStatus = sr.getStatus(); if (searchRequestStatus == HttpSearchExecutionStatus.OK) { log.debug("MGET Processing results for get request(s)"); String responseBody = sr.getResult(); Map<String,String> mappedResults = processResults(responseBody); getResults.putAll(mappedResults); log.debug("MGET Completed, returning processed results."); } else if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_FAILURE) { log.warn("MGET Exception executing get request"); } else { if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_TIMEOUT) { log.warn("Request timeout executing search request"); } else { log.warn("Connection timeout executing search request"); } } long time = (System.nanoTime() - startNanos) / 1000000; getResults.put(keyForTiming,Long.toString(time)); return getResults; }
ElasticSearchRelatedItemHttpGetRepository implements RelatedItemGetRepository { @Override public Map<String, String> getRelatedItemDocument(String[] ids) { Map<String,String> getResults = RelatedItemNoopGetRepository.getEmptyResults(ids); log.debug("MGET request to execute {} get request", ids.length); String arrayString = createArray(ids); String jsonStart = "{\"ids\":"; StringBuilder b = new StringBuilder(arrayString.length()+jsonStart.length()+1); b.append(jsonStart).append(arrayString).append('}'); String searchJson = b.toString(); log.debug("MGET request json is {}",searchJson); SearchResultEventWithSearchRequestKey[] results; HttpResult sr; long startNanos = System.nanoTime(); sr = elasticClient.executeSearch(HttpMethod.POST,url,searchJson); HttpSearchExecutionStatus searchRequestStatus = sr.getStatus(); if (searchRequestStatus == HttpSearchExecutionStatus.OK) { log.debug("MGET Processing results for get request(s)"); String responseBody = sr.getResult(); Map<String,String> mappedResults = processResults(responseBody); getResults.putAll(mappedResults); log.debug("MGET Completed, returning processed results."); } else if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_FAILURE) { log.warn("MGET Exception executing get request"); } else { if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_TIMEOUT) { log.warn("Request timeout executing search request"); } else { log.warn("Connection timeout executing search request"); } } long time = (System.nanoTime() - startNanos) / 1000000; getResults.put(keyForTiming,Long.toString(time)); return getResults; } }
ElasticSearchRelatedItemHttpGetRepository implements RelatedItemGetRepository { @Override public Map<String, String> getRelatedItemDocument(String[] ids) { Map<String,String> getResults = RelatedItemNoopGetRepository.getEmptyResults(ids); log.debug("MGET request to execute {} get request", ids.length); String arrayString = createArray(ids); String jsonStart = "{\"ids\":"; StringBuilder b = new StringBuilder(arrayString.length()+jsonStart.length()+1); b.append(jsonStart).append(arrayString).append('}'); String searchJson = b.toString(); log.debug("MGET request json is {}",searchJson); SearchResultEventWithSearchRequestKey[] results; HttpResult sr; long startNanos = System.nanoTime(); sr = elasticClient.executeSearch(HttpMethod.POST,url,searchJson); HttpSearchExecutionStatus searchRequestStatus = sr.getStatus(); if (searchRequestStatus == HttpSearchExecutionStatus.OK) { log.debug("MGET Processing results for get request(s)"); String responseBody = sr.getResult(); Map<String,String> mappedResults = processResults(responseBody); getResults.putAll(mappedResults); log.debug("MGET Completed, returning processed results."); } else if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_FAILURE) { log.warn("MGET Exception executing get request"); } else { if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_TIMEOUT) { log.warn("Request timeout executing search request"); } else { log.warn("Connection timeout executing search request"); } } long time = (System.nanoTime() - startNanos) / 1000000; getResults.put(keyForTiming,Long.toString(time)); return getResults; } ElasticSearchRelatedItemHttpGetRepository(Configuration configuration,
                                                     HttpElasticSearchClientFactory factory); }
ElasticSearchRelatedItemHttpGetRepository implements RelatedItemGetRepository { @Override public Map<String, String> getRelatedItemDocument(String[] ids) { Map<String,String> getResults = RelatedItemNoopGetRepository.getEmptyResults(ids); log.debug("MGET request to execute {} get request", ids.length); String arrayString = createArray(ids); String jsonStart = "{\"ids\":"; StringBuilder b = new StringBuilder(arrayString.length()+jsonStart.length()+1); b.append(jsonStart).append(arrayString).append('}'); String searchJson = b.toString(); log.debug("MGET request json is {}",searchJson); SearchResultEventWithSearchRequestKey[] results; HttpResult sr; long startNanos = System.nanoTime(); sr = elasticClient.executeSearch(HttpMethod.POST,url,searchJson); HttpSearchExecutionStatus searchRequestStatus = sr.getStatus(); if (searchRequestStatus == HttpSearchExecutionStatus.OK) { log.debug("MGET Processing results for get request(s)"); String responseBody = sr.getResult(); Map<String,String> mappedResults = processResults(responseBody); getResults.putAll(mappedResults); log.debug("MGET Completed, returning processed results."); } else if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_FAILURE) { log.warn("MGET Exception executing get request"); } else { if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_TIMEOUT) { log.warn("Request timeout executing search request"); } else { log.warn("Connection timeout executing search request"); } } long time = (System.nanoTime() - startNanos) / 1000000; getResults.put(keyForTiming,Long.toString(time)); return getResults; } ElasticSearchRelatedItemHttpGetRepository(Configuration configuration,
                                                     HttpElasticSearchClientFactory factory); @Override Map<String, String> getRelatedItemDocument(String[] ids); @Override void shutdown(); static Map<String,String> processResults(String responseBody); static Map<String,String> parseDocs(JSONArray array); }
ElasticSearchRelatedItemHttpGetRepository implements RelatedItemGetRepository { @Override public Map<String, String> getRelatedItemDocument(String[] ids) { Map<String,String> getResults = RelatedItemNoopGetRepository.getEmptyResults(ids); log.debug("MGET request to execute {} get request", ids.length); String arrayString = createArray(ids); String jsonStart = "{\"ids\":"; StringBuilder b = new StringBuilder(arrayString.length()+jsonStart.length()+1); b.append(jsonStart).append(arrayString).append('}'); String searchJson = b.toString(); log.debug("MGET request json is {}",searchJson); SearchResultEventWithSearchRequestKey[] results; HttpResult sr; long startNanos = System.nanoTime(); sr = elasticClient.executeSearch(HttpMethod.POST,url,searchJson); HttpSearchExecutionStatus searchRequestStatus = sr.getStatus(); if (searchRequestStatus == HttpSearchExecutionStatus.OK) { log.debug("MGET Processing results for get request(s)"); String responseBody = sr.getResult(); Map<String,String> mappedResults = processResults(responseBody); getResults.putAll(mappedResults); log.debug("MGET Completed, returning processed results."); } else if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_FAILURE) { log.warn("MGET Exception executing get request"); } else { if (searchRequestStatus == HttpSearchExecutionStatus.REQUEST_TIMEOUT) { log.warn("Request timeout executing search request"); } else { log.warn("Connection timeout executing search request"); } } long time = (System.nanoTime() - startNanos) / 1000000; getResults.put(keyForTiming,Long.toString(time)); return getResults; } ElasticSearchRelatedItemHttpGetRepository(Configuration configuration,
                                                     HttpElasticSearchClientFactory factory); @Override Map<String, String> getRelatedItemDocument(String[] ids); @Override void shutdown(); static Map<String,String> processResults(String responseBody); static Map<String,String> parseDocs(JSONArray array);  }