コード例 #1
0
 @Override
 public Map getMapping(String indexName, String type) {
   Assert.notNull(indexName, "No index defined for putMapping()");
   Assert.notNull(type, "No type defined for putMapping()");
   Map mappings = null;
   try {
     mappings =
         client
             .admin()
             .indices()
             .getMappings(new GetMappingsRequest().indices(indexName).types(type))
             .actionGet()
             .getMappings()
             .get(indexName)
             .get(type)
             .getSourceAsMap();
   } catch (Exception e) {
     throw new ElasticsearchException(
         "Error while getting mapping for indexName : "
             + indexName
             + " type : "
             + type
             + " "
             + e.getMessage());
   }
   return mappings;
 }
コード例 #2
0
  public static String readFileFromClasspath(String url) {
    StringBuilder stringBuilder = new StringBuilder();

    BufferedReader bufferedReader = null;

    try {
      ClassPathResource classPathResource = new ClassPathResource(url);
      InputStreamReader inputStreamReader =
          new InputStreamReader(classPathResource.getInputStream());
      bufferedReader = new BufferedReader(inputStreamReader);
      String line;

      while ((line = bufferedReader.readLine()) != null) {
        stringBuilder.append(line);
      }
    } catch (Exception e) {
      logger.debug(String.format("Failed to load file from url: %s: %s", url, e.getMessage()));
      return null;
    } finally {
      if (bufferedReader != null)
        try {
          bufferedReader.close();
        } catch (IOException e) {
          logger.debug(String.format("Unable to close buffered reader.. %s", e.getMessage()));
        }
    }

    return stringBuilder.toString();
  }