use of de.tblsoft.solr.pipeline.filter.SimpleMapping in project solr-cmd-utils by tblsoft.
the class ElasticJsonPathReader method read.
public void read() {
String response = "";
String pagedUrl = "";
String scrollId = "";
boolean hasHits = false;
SimpleMapping simpleMapping = new SimpleMapping(getPropertyAsList("mapping", new ArrayList<String>()));
Map<String, List<String>> mapping = simpleMapping.getMapping();
try {
url = getProperty("url", null);
scroll = getProperty("scroll", "1m");
String scrollBaseUrl = ElasticHelper.getScrollUrl(url);
pagedUrl = url + "&scroll=" + scroll;
do {
response = HTTPHelper.get(pagedUrl);
DocumentContext context = JsonPath.parse(response);
scrollId = context.read("$['_scroll_id']");
List<Object> elasticHits = context.read("$['hits']['hits'][*]['_source']");
hasHits = false;
int count = 0;
for (Object obj : elasticHits) {
hasHits = true;
Document document = new Document();
for (Map.Entry<String, List<String>> mappingEntry : mapping.entrySet()) {
try {
Object parsedValue = JsonPath.parse(obj).read(mappingEntry.getKey());
for (String target : mappingEntry.getValue()) {
document.setField(target, parsedValue);
}
} catch (PathNotFoundException e) {
// ignore
}
}
executer.document(document);
}
pagedUrl = scrollBaseUrl + "?scroll=" + scroll + "&scroll_id=" + scrollId;
} while (hasHits);
// executer.end();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of de.tblsoft.solr.pipeline.filter.SimpleMapping in project solr-cmd-utils by tblsoft.
the class JsonPathReader method read.
public void read() {
SimpleMapping simpleMapping = new SimpleMapping(getPropertyAsList("mapping", new ArrayList<String>()));
Map<String, List<String>> mapping = simpleMapping.getMapping();
try {
String rootPath = getProperty("rootPath", "$");
DocumentContext context = loadJsonContext();
List<Object> jsonHits = context.read(rootPath);
for (Object obj : jsonHits) {
Document document = new Document();
for (Map.Entry<String, List<String>> mappingEntry : mapping.entrySet()) {
try {
Object parsedValue = JsonPath.parse(obj).read(mappingEntry.getKey());
for (String target : mappingEntry.getValue()) {
document.setField(target, parsedValue);
}
} catch (PathNotFoundException e) {
// ignore
}
}
executer.document(document);
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations