Package org.elasticsearch.action.admin.indices.create

Examples of org.elasticsearch.action.admin.indices.create.CreateIndexRequest


        Map<String, String> keywordLowercase = Maps.newHashMap();
        keywordLowercase.put("tokenizer", "keyword");
        keywordLowercase.put("filter", "lowercase");
        settings.put("index.analysis.analyzer.analyzer_keyword", keywordLowercase);

        CreateIndexRequest cir = new CreateIndexRequest(indexName);
        cir.settings(settings);

        final ActionFuture<CreateIndexResponse> createFuture = c.admin().indices().create(cir);
        final boolean acknowledged = createFuture.actionGet().isAcknowledged();
        if (!acknowledged) {
            return false;
View Full Code Here


                        "\"_parent\": {" +
                        "\"type\" : \"content\"" +
                        "}}}";

        try {
            client.admin().indices().create(new CreateIndexRequest(INDEX_NAME).mapping(CHILD_TYPE_NAME, mapping)).actionGet();
        } catch (RemoteTransportException e) {
            // usually means the index is already created.
        }
    }
View Full Code Here

     * @param index The index to create
     * @return The index create request
     * @see org.elasticsearch.client.IndicesAdminClient#create(org.elasticsearch.action.admin.indices.create.CreateIndexRequest)
     */
    public static CreateIndexRequest createIndexRequest(String index) {
        return new CreateIndexRequest(index);
    }
View Full Code Here

        if (autoCreateIndex) {
            final AtomicInteger counter = new AtomicInteger(indices.size());
            final AtomicBoolean failed = new AtomicBoolean();
            for (String index : indices) {
                if (!clusterService.state().metaData().hasConcreteIndex(index)) {
                    createIndexAction.execute(new CreateIndexRequest(index).cause("auto(bulk api)"), new ActionListener<CreateIndexResponse>() {
                        @Override public void onResponse(CreateIndexResponse result) {
                            if (counter.decrementAndGet() == 0) {
                                executeBulk(bulkRequest, startTime, listener);
                            }
                        }
View Full Code Here

* @author kimchy (shay.banon)
*/
public class CreateIndexRequestBuilder extends BaseIndicesRequestBuilder<CreateIndexRequest, CreateIndexResponse> {

    public CreateIndexRequestBuilder(IndicesAdminClient indicesClient, String index) {
        super(indicesClient, new CreateIndexRequest(index));
    }
View Full Code Here

        controller.registerHandler(RestRequest.Method.POST, "/{index}", this);
    }

    @SuppressWarnings({"unchecked"})
    @Override public void handleRequest(final RestRequest request, final RestChannel channel) {
        CreateIndexRequest createIndexRequest = new CreateIndexRequest(request.param("index"));
        if (request.hasContent()) {
            XContentType xContentType = XContentFactory.xContentType(request.contentByteArray(), request.contentByteArrayOffset(), request.contentLength());
            if (xContentType != null) {
                try {
                    Map<String, Object> source = XContentFactory.xContent(xContentType)
                            .createParser(request.contentByteArray(), request.contentByteArrayOffset(), request.contentLength()).mapAndClose();
                    boolean found = false;
                    if (source.containsKey("settings")) {
                        createIndexRequest.settings((Map<String, Object>) source.get("settings"));
                        found = true;
                    }
                    if (source.containsKey("mappings")) {
                        found = true;
                        Map<String, Object> mappings = (Map<String, Object>) source.get("mappings");
                        for (Map.Entry<String, Object> entry : mappings.entrySet()) {
                            createIndexRequest.mapping(entry.getKey(), (Map<String, Object>) entry.getValue());
                        }
                    }
                    if (!found) {
                        // the top level are settings, use them
                        createIndexRequest.settings(source);
                    }
                } catch (Exception e) {
                    try {
                        channel.sendResponse(new XContentThrowableRestResponse(request, e));
                    } catch (IOException e1) {
                        logger.warn("Failed to send response", e1);
                        return;
                    }
                }
            } else {
                // its plain settings, parse and set them
                try {
                    createIndexRequest.settings(request.contentAsString());
                } catch (Exception e) {
                    try {
                        channel.sendResponse(new XContentThrowableRestResponse(request, BAD_REQUEST, new SettingsException("Failed to parse index settings", e)));
                    } catch (IOException e1) {
                        logger.warn("Failed to send response", e1);
                        return;
                    }
                }
            }
        }

        createIndexRequest.timeout(request.paramAsTime("timeout", timeValueSeconds(10)));

        client.admin().indices().create(createIndexRequest, new ActionListener<CreateIndexResponse>() {
            @Override public void onResponse(CreateIndexResponse response) {
                try {
                    XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
View Full Code Here

    }

    @Override protected void doExecute(final DeleteRequest request, final ActionListener<DeleteResponse> listener) {
        if (autoCreateIndex && !clusterService.state().metaData().hasConcreteIndex(request.index())) {
            request.beforeLocalFork();
            createIndexAction.execute(new CreateIndexRequest(request.index()), new ActionListener<CreateIndexResponse>() {
                @Override public void onResponse(CreateIndexResponse result) {
                    innerExecute(request, listener);
                }

                @Override public void onFailure(Throwable e) {
View Full Code Here

                request.opType(IndexRequest.OpType.CREATE);
            }
        }
        if (autoCreateIndex && !clusterService.state().metaData().hasConcreteIndex(request.index())) {
            request.beforeLocalFork(); // we fork on another thread...
            createIndexAction.execute(new CreateIndexRequest(request.index()).cause("auto(index api)"), new ActionListener<CreateIndexResponse>() {
                @Override public void onResponse(CreateIndexResponse result) {
                    innerExecute(request, listener);
                }

                @Override public void onFailure(Throwable e) {
View Full Code Here

*/
@SuppressWarnings("unused")
public class CreateIndexRequestBuilder<JsonInput, JsonOutput> extends AbstractRequestBuilderJsonOutput<CreateIndexRequest, CreateIndexResponse, JsonInput, JsonOutput> {

    public CreateIndexRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
        super(client, new CreateIndexRequest(null), jsonToString, stringToJson);
    }
View Full Code Here

        Settings searchIndexSettings = indexData.settings();
        ImmutableSettings.Builder settingBuilder = ImmutableSettings.settingsBuilder().put(searchIndexSettings);
        if (newIndexShards > 0)
            settingBuilder.put("index.number_of_shards", newIndexShards);
           
        CreateIndexRequest createReq;
       
        if(type.equals("*")) {
            createReq = new CreateIndexRequest(newIndex);
            for(ObjectObjectCursor<String, MappingMetaData> mapCursor : indexData.mappings()) {
                createReq.mapping(mapCursor.key, mapCursor.value.sourceAsMap());
            }
            createReq.settings(settingBuilder.build());
        }
        else {
            MappingMetaData mappingMeta = indexData.mapping(type);
            createReq = new CreateIndexRequest(newIndex).
                mapping(type, mappingMeta.sourceAsMap()).
                settings(settingBuilder.build());
        }

        client.admin().indices().create(createReq).actionGet();
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.admin.indices.create.CreateIndexRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.