Hi Fidea,

When specifying an ID, the IndexedRequest[1] can perform a complete overwrite. 
If partial update is needed, the UpdateRequest[2] can be used.

@Override
public void process(
        Tuple2<Integer, String> element, RuntimeContext ctx, RequestIndexer 
indexer) {
    UpdateRequest updateRequest = new UpdateRequest("index-name", "id-123");
    Map<String, Object> jsonMap = new HashMap<>();
    jsonMap.put("updated", new Date());
    jsonMap.put("reason", "daily update");
    updateRequest.doc(jsonMap);
    indexer.add(updateRequest);
}


Best,
Jiabao

[1] 
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-index.html
[2] 
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-update.html


On 2024/01/29 16:14:26 Fidea Lidea wrote:
> Hi  Jiabao & Jiadong,
> 
> Could you please share examples on how to "*update*" data using
> ElasticsearchSink?
> 
> Thanks
> 
> On Mon, Jan 29, 2024 at 9:07 PM Jiabao Sun <ji...@xtransfer.cn> wrote:
> 
> > Hi Fidea,
> >
> > I found some examples in the Java documentation, and I hope they can be
> > helpful.
> >
> > private static class TestElasticSearchSinkFunction implements
> > ElasticsearchSinkFunction<Tuple2<Integer, String>> {
> >     public IndexRequest createIndexRequest(Tuple2<Integer, String>
> > element) {
> >         Map<String, Object> json = new HashMap<>();
> >         json.put("data", element.f1);
> >         return Requests
> >                 .indexRequest()
> >                 .index("my-index")
> >                 .type("my-type")
> >                 .id(element.f0.toString())
> >                 .source(json);
> >     }
> >
> >     public void process(
> >             Tuple2<Integer, String> element,
> >             RuntimeContext ctx,
> >             RequestIndexer indexer) {
> >         indexer.add(createIndexRequest(element));
> >     }
> > }
> >
> > But as jiadong mentioned, ElasticsearchSinkFunction is no longer
> > recommended for use.
> >
> > Best,
> > Jiabao
> >
> >
> > On 2024/01/29 11:15:43 Fidea Lidea wrote:
> > > Hi Team,
> > >
> > > Could you please share with me a few example codes on  how to perform
> > > "updaterequest on elasticsearch using apache flink"
> > > I.want to use  ElasticsearchSinkFunction to perform updaterequest.
> > >
> > > Thanks
> > > Nida Shaikh
> > > lideafidea...@gmail.com
> > >
> 

Reply via email to