com.github.joschi.nosqlunit.elasticsearch.http.parser.DataReader Maven / Gradle / Ivy
package com.github.joschi.nosqlunit.elasticsearch.http.parser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.MoreObjects;
import io.searchbox.client.JestClient;
import io.searchbox.client.JestResult;
import io.searchbox.core.Bulk;
import io.searchbox.core.BulkResult;
import io.searchbox.core.Index;
import io.searchbox.indices.CreateIndex;
import io.searchbox.indices.Refresh;
import io.searchbox.indices.template.DeleteTemplate;
import io.searchbox.indices.template.PutTemplate;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UncheckedIOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class DataReader {
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
public static final String DOCUMENTS_ELEMENT = "documents";
public static final String DOCUMENT_ELEMENT = "document";
public static final String DATA_ELEMENT = "data";
public static final String INDEX_ELEMENT = "index";
public static final String INDEX_NAME_ELEMENT = "indexName";
public static final String INDEX_TYPE_ELEMENT = "indexType";
public static final String INDEX_ID_ELEMENT = "indexId";
private final JestClient client;
private final boolean createIndices;
private final Map indexSettings;
private final Map> templates;
public DataReader(JestClient client,
boolean createIndices,
Map indexSettings,
Map> templates) {
this.client = client;
this.createIndices = createIndices;
this.indexSettings = indexSettings;
this.templates = templates;
}
public void read(InputStream data) {
try {
final List