Reindex using REST api and high level client

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?

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();
}

}

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