Search in sources :

Example 16 with CreateIndexRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest in project drill by apache.

the class ElasticSearchQueryTest method prepareData.

private static void prepareData() throws IOException {
    restHighLevelClient = new RestHighLevelClient(RestClient.builder(HttpHost.create(HOST)));
    indexName = "employee";
    CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
    restHighLevelClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);
    XContentBuilder builder = XContentFactory.jsonBuilder();
    builder.startObject();
    builder.field("employee_id", 1);
    builder.field("full_name", "Sheri Nowmer");
    builder.field("first_name", "Sheri");
    builder.field("last_name", "Nowmer");
    builder.field("position_id", 1);
    builder.field("position_title", "President");
    builder.field("store_id", 0);
    builder.field("department_id", 1);
    builder.field("birth_date", "1961-08-26");
    builder.field("hire_date", "1994-12-01 00:00:00.0");
    builder.field("salary", 80000.0);
    builder.field("supervisor_id", 0);
    builder.field("education_level", "Graduate Degree");
    builder.field("marital_status", "S");
    builder.field("gender", "F");
    builder.field("management_role", "Senior Management");
    builder.endObject();
    IndexRequest indexRequest = new IndexRequest(indexName).source(builder);
    restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
    builder = XContentFactory.jsonBuilder();
    builder.startObject();
    builder.field("employee_id", 2);
    builder.field("full_name", "Derrick Whelply");
    builder.field("first_name", "Derrick");
    builder.field("last_name", "Whelply");
    builder.field("position_id", 2);
    builder.field("position_title", "VP Country Manager");
    builder.field("store_id", 0);
    builder.field("department_id", 1);
    builder.field("birth_date", "1915-07-03");
    builder.field("hire_date", "1994-12-01 00:00:00.0");
    builder.field("salary", 40000.0);
    builder.field("supervisor_id", 1);
    builder.field("education_level", "Graduate Degree");
    builder.field("marital_status", "M");
    builder.field("gender", "M");
    builder.field("management_role", "Senior Management");
    builder.endObject();
    indexRequest = new IndexRequest(indexName).source(builder);
    restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
    builder = XContentFactory.jsonBuilder();
    builder.startObject();
    builder.field("employee_id", 4);
    builder.field("full_name", "Michael Spence");
    builder.field("first_name", "Michael");
    builder.field("last_name", "Spence");
    builder.field("position_id", 2);
    builder.field("position_title", "VP Country Manager");
    builder.field("store_id", 0);
    builder.field("department_id", 1);
    builder.field("birth_date", "1969-06-20");
    builder.field("hire_date", "1998-01-01 00:00:00.0");
    builder.field("salary", 40000.0);
    builder.field("supervisor_id", 1);
    builder.field("education_level", "Graduate Degree");
    builder.field("marital_status", "S");
    builder.field("gender", "M");
    builder.field("management_role", "Senior Management");
    builder.endObject();
    indexRequest = new IndexRequest(indexName).source(builder);
    restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
    builder = XContentFactory.jsonBuilder();
    builder.startObject();
    builder.field("employee_id", 5);
    builder.field("full_name", "Maya Gutierrez");
    builder.field("first_name", "Maya");
    builder.field("last_name", "Gutierrez");
    builder.field("position_id", 2);
    builder.field("position_title", "VP Country Manager");
    builder.field("store_id", 0);
    builder.field("department_id", 1);
    builder.field("birth_date", "1951-05-10");
    builder.field("hire_date", "1998-01-01 00:00:00.0");
    builder.field("salary", 35000.0);
    builder.field("supervisor_id", 1);
    builder.field("education_level", "Bachelors Degree");
    builder.field("marital_status", "M");
    builder.field("gender", "F");
    builder.field("management_role", "Senior Management");
    builder.endObject();
    indexRequest = new IndexRequest(indexName).source(builder);
    restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
    builder = XContentFactory.jsonBuilder();
    builder.startObject();
    builder.field("employee_id", 6);
    builder.field("full_name", "Roberta Damstra");
    builder.field("first_name", "Roberta");
    builder.field("last_name", "Damstra");
    builder.field("position_id", 3);
    builder.field("position_title", "VP Information Systems");
    builder.field("store_id", 0);
    builder.field("department_id", 2);
    builder.field("birth_date", "1942-10-08");
    builder.field("hire_date", "1994-12-01 00:00:00.0");
    builder.field("salary", 25000.0);
    builder.field("supervisor_id", 1);
    builder.field("education_level", "Bachelors Degree");
    builder.field("marital_status", "M");
    builder.field("gender", "F");
    builder.field("management_role", "Senior Management");
    builder.endObject();
    indexRequest = new IndexRequest(indexName).source(builder);
    restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
    builder = XContentFactory.jsonBuilder();
    builder.startObject();
    builder.field("employee_id", 7);
    builder.field("full_name", "Rebecca Kanagaki");
    builder.field("first_name", "Rebecca");
    builder.field("last_name", "Kanagaki");
    builder.field("position_id", 4);
    builder.field("position_title", "VP Human Resources");
    builder.field("store_id", 0);
    builder.field("department_id", 3);
    builder.field("birth_date", "1949-03-27");
    builder.field("hire_date", "1994-12-01 00:00:00.0");
    builder.field("salary", 15000.0);
    builder.field("supervisor_id", 1);
    builder.field("education_level", "Bachelors Degree");
    builder.field("marital_status", "M");
    builder.field("gender", "F");
    builder.field("management_role", "Senior Management");
    builder.endObject();
    indexRequest = new IndexRequest(indexName).source(builder);
    restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
    builder = XContentFactory.jsonBuilder();
    builder.startObject();
    builder.field("employee_id", 8);
    builder.field("full_name", "Kim Brunner");
    builder.field("first_name", "Kim");
    builder.field("last_name", "Brunner");
    builder.field("position_id", 11);
    builder.field("position_title", "Store Manager");
    builder.field("store_id", 9);
    builder.field("department_id", 11);
    builder.field("birth_date", "1922-08-10");
    builder.field("hire_date", "1998-01-01 00:00:00.0");
    builder.field("salary", 10000.0);
    builder.field("supervisor_id", 5);
    builder.field("education_level", "Bachelors Degree");
    builder.field("marital_status", "S");
    builder.field("gender", "F");
    builder.field("management_role", "Store Management");
    builder.endObject();
    indexRequest = new IndexRequest(indexName).source(builder);
    restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
    builder = XContentFactory.jsonBuilder();
    builder.startObject();
    builder.field("employee_id", 9);
    builder.field("full_name", "Brenda Blumberg");
    builder.field("first_name", "Brenda");
    builder.field("last_name", "Blumberg");
    builder.field("position_id", 11);
    builder.field("position_title", "Store Manager");
    builder.field("store_id", 21);
    builder.field("department_id", 11);
    builder.field("birth_date", "1979-06-23");
    builder.field("hire_date", "1998-01-01 00:00:00.0");
    builder.field("salary", 17000.0);
    builder.field("supervisor_id", 5);
    builder.field("education_level", "Graduate Degree");
    builder.field("marital_status", "M");
    builder.field("gender", "F");
    builder.field("management_role", "Store Management");
    builder.endObject();
    indexRequest = new IndexRequest(indexName).source(builder);
    restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
    builder = XContentFactory.jsonBuilder();
    builder.startObject();
    builder.field("employee_id", 10);
    builder.field("full_name", "Darren Stanz");
    builder.field("first_name", "Darren");
    builder.field("last_name", "Stanz");
    builder.field("position_id", 5);
    builder.field("position_title", "VP Finance");
    builder.field("store_id", 0);
    builder.field("department_id", 5);
    builder.field("birth_date", "1949-08-26");
    builder.field("hire_date", "1994-12-01 00:00:00.0");
    builder.field("salary", 50000.0);
    builder.field("supervisor_id", 1);
    builder.field("education_level", "Partial College");
    builder.field("marital_status", "M");
    builder.field("gender", "M");
    builder.field("management_role", "Senior Management");
    builder.endObject();
    indexRequest = new IndexRequest(indexName).source(builder);
    restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
    builder = XContentFactory.jsonBuilder();
    builder.startObject();
    builder.field("employee_id", 11);
    builder.field("full_name", "Jonathan Murraiin");
    builder.field("first_name", "Jonathan");
    builder.field("last_name", "Murraiin");
    builder.field("position_id", 11);
    builder.field("position_title", "Store Manager");
    builder.field("store_id", 1);
    builder.field("department_id", 11);
    builder.field("birth_date", "1967-06-20");
    builder.field("hire_date", "1998-01-01 00:00:00.0");
    builder.field("salary", 15000.0);
    builder.field("supervisor_id", 5);
    builder.field("education_level", "Graduate Degree");
    builder.field("marital_status", "S");
    builder.field("gender", "M");
    builder.field("management_role", "Store Management");
    builder.endObject();
    indexRequest = new IndexRequest(indexName).source(builder);
    restHighLevelClient.index(indexRequest, RequestOptions.DEFAULT);
    restHighLevelClient.indices().refresh(new RefreshRequest(indexName), RequestOptions.DEFAULT);
}
Also used : RefreshRequest(org.elasticsearch.action.admin.indices.refresh.RefreshRequest) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) DeleteIndexRequest(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 17 with CreateIndexRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest in project graylog2-server by Graylog2.

the class ClientES7 method createIndex.

@Override
public void createIndex(String index, int shards, int replicas) {
    LOG.debug("Creating index " + index);
    final CreateIndexRequest createIndexRequest = new CreateIndexRequest(index);
    createIndexRequest.settings(Settings.builder().put("index.number_of_shards", shards).put("index.number_of_replicas", replicas));
    client.execute((c, requestOptions) -> c.indices().create(createIndexRequest, requestOptions));
}
Also used : CreateIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest)

Example 18 with CreateIndexRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest in project graylog2-server by Graylog2.

the class FixtureImporterES7 method createIndex.

private void createIndex(String indexName) {
    final CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName).waitForActiveShards(ActiveShardCount.ONE);
    client.execute((c, requestOptions) -> c.indices().create(createIndexRequest, requestOptions));
}
Also used : CreateIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest)

Example 19 with CreateIndexRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest in project datashare by ICIJ.

the class ElasticsearchConfiguration method createIndex.

public static boolean createIndex(RestHighLevelClient client, String indexName) {
    GetIndexRequest request = new GetIndexRequest(indexName);
    try {
        if (!client.indices().exists(request, RequestOptions.DEFAULT)) {
            LOGGER.info("index {} does not exist, creating one", indexName);
            CreateIndexRequest createReq = new CreateIndexRequest(indexName);
            createReq.settings(getResourceContent(SETTINGS_RESOURCE_NAME), JSON);
            createReq.mapping(getResourceContent(MAPPING_RESOURCE_NAME), JSON);
            client.indices().create(createReq, RequestOptions.DEFAULT);
            return true;
        }
    } catch (IOException e) {
        throw new ConfigurationException(e);
    }
    return false;
}
Also used : GetIndexRequest(org.elasticsearch.client.indices.GetIndexRequest) IOException(java.io.IOException) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest)

Example 20 with CreateIndexRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest in project datashare by ICIJ.

the class ElasticsearchRule method before.

@Override
protected void before() throws Throwable {
    GetIndexRequest request = new GetIndexRequest(indexName);
    if (!client.indices().exists(request, RequestOptions.DEFAULT)) {
        CreateIndexRequest createReq = new CreateIndexRequest(indexName);
        byte[] settings = toByteArray(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(SETTINGS_RESOURCE_NAME)));
        createReq.settings(new String(settings), JSON);
        byte[] mapping = toByteArray(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(MAPPING_RESOURCE_NAME)));
        createReq.mapping(new String(mapping), JSON);
        client.indices().create(createReq, RequestOptions.DEFAULT);
    }
}
Also used : GetIndexRequest(org.elasticsearch.client.indices.GetIndexRequest) CreateIndexRequest(org.elasticsearch.client.indices.CreateIndexRequest)

Aggregations

CreateIndexRequest (org.elasticsearch.client.indices.CreateIndexRequest)17 IOException (java.io.IOException)6 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)6 IndexRequest (org.elasticsearch.action.index.IndexRequest)5 GetIndexRequest (org.elasticsearch.client.indices.GetIndexRequest)5 RefreshRequest (org.elasticsearch.action.admin.indices.refresh.RefreshRequest)4 RestHighLevelClient (org.elasticsearch.client.RestHighLevelClient)4 CreateIndexResponse (org.elasticsearch.client.indices.CreateIndexResponse)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)4 CreateIndexRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.CreateIndexRequest)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AcknowledgedResponse (org.elasticsearch.action.support.master.AcknowledgedResponse)2 DocumentMapping (com.b2international.index.mapping.DocumentMapping)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Retryer (com.github.rholder.retry.Retryer)1 RetryerBuilder (com.github.rholder.retry.RetryerBuilder)1 StopStrategies (com.github.rholder.retry.StopStrategies)1