use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project incubator-sdap-mudrod by apache.
the class TrainingImporter method importTrainingSet.
/**
* Method of importing training set in to Elasticsearch
*
* @param dataFolder the path to the traing set
* @throws IOException IOException
*/
public void importTrainingSet(String dataFolder) throws IOException {
es.createBulkProcessor();
File[] files = new File(dataFolder).listFiles();
for (File file : files) {
BufferedReader br = new BufferedReader(new FileReader(file.getAbsolutePath()));
br.readLine();
String line = br.readLine();
while (line != null) {
String[] list = line.split(",");
String query = file.getName().replace(".csv", "");
if (list.length > 0) {
IndexRequest ir = new IndexRequest(props.getProperty(MudrodConstants.ES_INDEX_NAME), "trainingranking").source(jsonBuilder().startObject().field("query", query).field("dataID", list[0]).field("label", list[list.length - 1]).endObject());
es.getBulkProcessor().add(ir);
}
line = br.readLine();
}
br.close();
}
es.destroyBulkProcessor();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project incubator-sdap-mudrod by apache.
the class ImportMetadata method importToES.
/**
* importToES: Index metadata into elasticsearch from local file directory.
* Please make sure metadata have been harvest from web service before
* invoking this method.
*/
private void importToES() {
es.deleteType(props.getProperty(MudrodConstants.ES_INDEX_NAME), MudrodConstants.RECOM_METADATA_TYPE);
es.createBulkProcessor();
File directory = new File(props.getProperty(MudrodConstants.RAW_METADATA_PATH));
File[] fList = directory.listFiles();
for (File file : fList) {
InputStream is;
try {
is = new FileInputStream(file);
try {
String jsonTxt = IOUtils.toString(is);
JsonParser parser = new JsonParser();
JsonElement item = parser.parse(jsonTxt);
IndexRequest ir = new IndexRequest(props.getProperty(MudrodConstants.ES_INDEX_NAME), MudrodConstants.RECOM_METADATA_TYPE).source(item.toString());
es.getBulkProcessor().add(ir);
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
es.destroyBulkProcessor();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project incubator-sdap-mudrod by apache.
the class LinkageTriple method insertTriples.
public static void insertTriples(ESDriver es, List<LinkageTriple> triples, String index, String type, Boolean bTriple, boolean bSymmetry) throws IOException {
es.deleteType(index, type);
if (bTriple) {
LinkageTriple.addMapping(es, index, type);
}
if (triples == null) {
return;
}
es.createBulkProcessor();
for (LinkageTriple triple : triples) {
XContentBuilder jsonBuilder = jsonBuilder().startObject();
if (bTriple) {
jsonBuilder.field("concept_A", triple.keyA);
jsonBuilder.field("concept_B", triple.keyB);
} else {
jsonBuilder.field("keywords", triple.keyA + "," + triple.keyB);
}
jsonBuilder.field("weight", Double.parseDouble(df.format(triple.weight)));
jsonBuilder.endObject();
IndexRequest ir = new IndexRequest(index, type).source(jsonBuilder);
es.getBulkProcessor().add(ir);
if (bTriple && bSymmetry) {
XContentBuilder symmetryJsonBuilder = jsonBuilder().startObject();
symmetryJsonBuilder.field("concept_A", triple.keyB);
symmetryJsonBuilder.field("concept_B", triple.keyA);
symmetryJsonBuilder.field("weight", Double.parseDouble(df.format(triple.weight)));
symmetryJsonBuilder.endObject();
IndexRequest symmetryir = new IndexRequest(index, type).source(symmetryJsonBuilder);
es.getBulkProcessor().add(symmetryir);
}
}
es.destroyBulkProcessor();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project drill by apache.
the class ElasticInfoSchemaTest method prepareData.
private static void prepareData() throws IOException {
restHighLevelClient = new RestHighLevelClient(RestClient.builder(HttpHost.create(HOST)));
String indexName = "t1";
indexNames.add(indexName);
CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
restHighLevelClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("string_field", "a");
builder.field("int_field", 123);
builder.endObject();
IndexRequest indexRequest = new IndexRequest(indexName).source(builder);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
restHighLevelClient.indices().refresh(new RefreshRequest(indexName), RequestOptions.DEFAULT);
indexName = "t2";
indexNames.add(indexName);
createIndexRequest = new CreateIndexRequest(indexName);
restHighLevelClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);
builder = XContentFactory.jsonBuilder();
builder.startObject();
builder.field("another_int_field", 321);
builder.field("another_string_field", "b");
builder.endObject();
indexRequest = new IndexRequest(indexName).source(builder);
restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
restHighLevelClient.indices().refresh(new RefreshRequest(indexName), RequestOptions.DEFAULT);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project samza by apache.
the class ElasticsearchSystemProducer method send.
@Override
public void send(String source, OutgoingMessageEnvelope envelope) {
IndexRequest indexRequest = indexRequestFactory.getIndexRequest(envelope);
sourceBulkProcessor.get(source).add(indexRequest);
}
Aggregations