use of org.elasticsearch.client.indices.CreateIndexRequest 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.elasticsearch.client.indices.CreateIndexRequest in project graylog2-server by Graylog2.
the class ClientES7 method bulkIndex.
@Override
public void bulkIndex(BulkIndexRequest bulkIndexRequest) {
final BulkRequest bulkRequest = new BulkRequest();
bulkRequest.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
bulkIndexRequest.requests().forEach((indexName, documents) -> documents.forEach(doc -> bulkRequest.add(createIndexRequest(indexName, doc))));
client.execute((c, requestOptions) -> c.bulk(bulkRequest, requestOptions));
}
use of org.elasticsearch.client.indices.CreateIndexRequest in project graylog2-server by Graylog2.
the class IndicesAdapterES7 method create.
@Override
public void create(String index, IndexSettings indexSettings) {
final Map<String, Object> settings = new HashMap<>();
settings.put("number_of_shards", indexSettings.shards());
settings.put("number_of_replicas", indexSettings.replicas());
final CreateIndexRequest request = new CreateIndexRequest(index).settings(settings);
client.execute((c, requestOptions) -> c.indices().create(request, requestOptions), "Unable to create index " + index);
}
use of org.elasticsearch.client.indices.CreateIndexRequest in project gora by apache.
the class ElasticsearchStore method createSchema.
@Override
public void createSchema() throws GoraException {
CreateIndexRequest request = new CreateIndexRequest(elasticsearchMapping.getIndexName());
Map<String, Object> properties = new HashMap<>();
for (Map.Entry<String, Field> entry : elasticsearchMapping.getFields().entrySet()) {
Map<String, Object> fieldType = new HashMap<>();
fieldType.put("type", entry.getValue().getDataType().getType().name().toLowerCase(Locale.ROOT));
if (entry.getValue().getDataType().getType() == Field.DataType.SCALED_FLOAT) {
fieldType.put("scaling_factor", entry.getValue().getDataType().getScalingFactor());
}
properties.put(entry.getKey(), fieldType);
}
// Special field for range query
properties.put("gora_id", new HashMap<String, Object>() {
{
put("type", "keyword");
}
});
Map<String, Object> mapping = new HashMap<>();
mapping.put("properties", properties);
request.mapping(mapping);
try {
if (!client.indices().exists(new GetIndexRequest(elasticsearchMapping.getIndexName()), RequestOptions.DEFAULT)) {
client.indices().create(request, RequestOptions.DEFAULT);
}
} catch (IOException ex) {
throw new GoraException(ex);
}
}
use of org.elasticsearch.client.indices.CreateIndexRequest in project sonarqube by SonarSource.
the class EsRequestDetailsTest method should_format_CreateIndexRequest.
@Test
public void should_format_CreateIndexRequest() {
CreateIndexRequest request = new CreateIndexRequest("index-1");
assertThat(EsRequestDetails.computeDetailsAsString(request)).isEqualTo("ES create index 'index-1'");
}
Aggregations