2017-09-13 2 views
0

색인이 생성 된 문서에 첨부 할 타임 스탬프를 만들려고합니다. 아래 명령을 통해 Query DSL에서 가능하다는 것을 알고 있습니다. Java API를 통해이를 수행하는 방법을 찾을 수 없습니다. 혹시이 일을 전에 한 적이 있니?ElasticSearch에서 자바 API를 통해 파이프 라인을 생성하고 사용하는 방법

감사합니다.

DELETE anindex 


PUT _ingest/pipeline/timestamp { 
    "description" : "describe pipeline", 
    "processors" : [{ 
         "set" : { 
           "field": "timestamp", 
           "value": "{{_ingest.timestamp}}" 
           } 
        }] 
       } 


PUT anindex 
{ 
    "mappings": { 
       "jeff": { 
         } 
       } 
} 


PUT anindex/jeff/id10?pipeline=timestamp 
{ 
    "hi": "jeff" 
} 


GET anindex/jeff/id10 
+0

내 이해에 따라, 당신은 이미 Ingest 파이프 라인 "타임 스탬프"를 정의했습니다. 이제는 매번 "timestamp"파이프 라인을 통해 전달하여 색인 문서에 JAVA API 만 필요합니다. 권리? –

+0

답장을 보내 주셔서 감사합니다! 좀 빠지는. 우리는 그 코드 전체를 java로 번역하고 싶습니다. 파이프 라인의 정의를 포함합니다. – Tameem

+0

하지만 왜 파이프 라인 정의를 매번 정의해야합니까? 데이터 삽입 또는 조작 전에 한 번 정의해야하는 일종의 메타 정보 또는 매핑입니다. –

답변

0

는 지금까지 내가 아는 한, Elasticsearch는 인제 스트 파이프 라인을 정의하기위한 자바 API가 없습니다. 주변의 일, 당신은 HttpURLConnection의 사용 JAVA에서 인제 스트 파이프 라인을 정의하기 위해 다음을 수행 할 수 있습니다으로 :

URL obj = new URL("http://localhost:9200/_ingest/pipeline/timestamp"); 
String json = "{\n" + 
     " \"description\": \"describe pipeline\",\n" + 
     " \"processors\": [\n" + 
     " {\n" + 
     "  \"set\": {\n" + 
     "  \"field\": \"timestamp\",\n" + 
     "  \"value\": \"{{_ingest.timestamp}}\"\n" + 
     "  }\n" + 
     " }\n" + 
     " ]\n" + 
     "}"; 
HttpURLConnection con = (HttpURLConnection) obj.openConnection(); 

con.setRequestMethod("PUT"); 
con.setDoInput(true); 
con.setDoOutput(true); 
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); 

OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream()); 
osw.write(json); 
osw.flush(); 
osw.close(); 

System.out.println(con.getResponseCode() + " : " + con.getResponseMessage()); 
if (con != null) 
    con.disconnect(); 

을 그리고 지금, 아래 만들어진 "타임 스탬프"를 통해 전달하여 인덱싱 문서의 자바 코드 파이프 라인을 인제 스트 :

TransportClient client = buildTransPortClient(); 

Map<String, Object> object = new HashMap<String, Object>(); 
object.put("user","kimchy"); 
object.put("postDate",new Date()); 
object.put("message","trying out Elasticsearch"); 

IndexResponse response = client.prepareIndex("test", "test", "100") 
     .setSource(object) 
     .setPipeline("timestamp") 
     .get(); 

System.out.println(response); 
관련 문제