자바 코드 인덱스 PDF 파일에 ElasticSearch을 파일?

다음은 내 코드입니다 :

            InputStream inputStream = new FileInputStream(new File("mypdf.pdf"));
        try {
            byte[]  fileByteStream = IOUtils.toByteArray(inputStream );
            String base64String = new String(Base64.getEncoder().encodeToString(fileByteStream).getBytes(),"UTF-8");
            String strEncoded = Base64.getEncoder().encodeToString( base64String.getBytes( "utf-8" ));
            this.stream.close();

                    JSONObject correspondenceNode = new JSONObject(); 
                    correspondenceNode.put("data",strEncoded );

                    String strSsonValues = correspondenceNode.toString();
                    HttpEntity entity = new NStringEntity(strSsonValues , ContentType.APPLICATION_JSON);
                    elasticrestClient.put("/2018/documents/"1, entity);

        } catch (IOException e) {
            e.printStackTrace();
        }

다음은 코드를 디코딩하고 있습니다 :

String responseBody = elasticrestClient.get("/2018/documents/1");
//some code to fetch the hits
JSONObject h = hitsArray.getJSONObject(0);
source = h.getJSONObject("_source");
String object = (source.getString("data"));
byte[] decodedStr = Base64.getDecoder().decode( object );

FileOutputStream fos = new FileOutputStream("download.pdf");
fos.write(Base64.getDecoder().decode(new String( decodedStr, "utf-8" )));
fos.close();

사용자 2018년 8월 2일에 대답 원치

추출 텍스트와 메타 데이터 및 바이너리 파일 자체에 URL을 가리 킵니다.

{ 
  "내용": "여기 추출 된 텍스트", 
  "메타": { 
    // 메타 데이터가 
  }, 
  "URL을": "파일 : // 경로 /로 / 파일" 
}
게시 된 298 개 원래 기사 · 원 찬양 (107) ·은 140,000 + 조회수

추천

출처blog.csdn.net/ywl470812087/article/details/104875188