How to create and use Pipelines via Java API in ElasticSearch -
i'm trying create timestamp attach documents indexed. know possible in query dsl via below set of commands. cannot find out how through java api. have of done before?
thanks!
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" } anindex/jeff/id10
as far know, elasticsearch doesn't have java api defining ingest pipeline. work around, can following define ingest pipeline java using httpurlconnection:
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();
and now, below java code indexing document passing them through created "timestamp" ingest pipeline:
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);
Comments
Post a Comment