# Reindex using REST api and high level client

**URL:** <https://discuss.elastic.co/t/reindex-using-rest-api-and-high-level-client/190119>\
**Category:** Elasticsearch\
**Created:** [July 11, 2019, 10:56pm UTC](https://discuss.elastic.co/t/reindex-using-rest-api-and-high-level-client/190119 "2019-07-11T22:56:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shradhatx](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shradhatx/32/45398_2.png) [@shradhatx](https://discuss.elastic.co/u/shradhatx)\
**Post date:** [July 11, 2019, 10:56pm UTC](https://discuss.elastic.co/t/reindex-using-rest-api-and-high-level-client/190119/1 "2019-07-11T22:56:18Z")

</div>

```
ReindexRequest request = new ReindexRequest();
        request.setSourceIndices("mytest");
        request.setDestIndex("mytest");
        request.setScroll(TimeValue.timeValueMinutes(5));
        request.setRemoteInfo(
            new RemoteInfo(
                    "http", "127.0.0.1", 9200,null,
                    new BytesArray(new 
                          MatchAllQueryBuilder().toString()),
                    null, null, Collections.emptyMap(),
                    new TimeValue(100, TimeUnit.MILLISECONDS),
                    new TimeValue(100, TimeUnit.SECONDS)
            )
    );
It doesn't like Collections.emptyMap(), gives an error : 
incompatible types: 
java.util.Map<java.lang.Object,java.lang.Object> cannot be 
converted to java.util.Map<java.lang.String,java.lang.String>

```

How do I fix it?

---

<div class="post-metadata">

**Author:** ![shradhatx](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shradhatx/32/45398_2.png) [@shradhatx](https://discuss.elastic.co/u/shradhatx)\
**Post date:** [July 15, 2019, 7:19pm UTC](https://discuss.elastic.co/t/reindex-using-rest-api-and-high-level-client/190119/2 "2019-07-15T19:19:39Z")

</div>

Here is a simple program that works  
import java.io.IOException;  
import org.elasticsearch.client.RestHighLevelClient;  
import org.elasticsearch.index.reindex.ReindexRequest;  
import org.elasticsearch.client.RestClient;  
import org.elasticsearch.index.reindex.BulkByScrollResponse;  
import org.elasticsearch.index.reindex.RemoteInfo;  
import org.elasticsearch.index.query.MatchAllQueryBuilder;  
import org.elasticsearch.client.RequestOptions;  
import org.elasticsearch.common.unit.TimeValue;  
import org.elasticsearch.common.bytes.BytesArray;  
import org.apache.http.HttpHost;

import java.util.concurrent.TimeUnit;  
import java.util.Collections;  
import java.util.Map;

public class ReindexIt {

```
public static void main(String[] args){

    System.out.println("Reindexing !!");
    RestHighLevelClient client = new RestHighLevelClient(
            RestClient.builder(
                    new HttpHost("localhost", 9203, "http")
               ));

    Map map = Collections.EMPTY_MAP;
    Map<String, String> d = Collections.emptyMap();

    ReindexRequest request = new ReindexRequest();
    request.setSourceIndices("mytest");
    request.setDestIndex("mytest1");
    request.setScroll(TimeValue.timeValueMinutes(5));
    request.setRemoteInfo(
            new RemoteInfo(
                    "http", "127.0.0.1", 9200,null,
                    new BytesArray(new MatchAllQueryBuilder().toString()),
                    null, null, d,
                    new TimeValue(100, TimeUnit.MILLISECONDS),
                    new TimeValue(100, TimeUnit.SECONDS)
            )
    );

    try {
        BulkByScrollResponse bulkResponse =
                client.reindex(request, RequestOptions.DEFAULT);
    } catch (IOException e) {System.out.println(e); }

    System.out.println("Done !!");
    //client.close();
}

```

}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 12, 2019, 7:19pm UTC](https://discuss.elastic.co/t/reindex-using-rest-api-and-high-level-client/190119/3 "2019-08-12T19:19:41Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
