
com.thematchbox.river.actions.IndexTools Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of AbstractRiver Show documentation
Show all versions of AbstractRiver Show documentation
This project contains an abstract implementation of an ElasticSearch River and is used as a basis for custom river implementations.
package com.thematchbox.river.actions;
/* Copyright 2015 theMatchBox
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
import org.elasticsearch.action.admin.indices.exists.types.TypesExistsRequest;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
public class IndexTools {
public static CreateIndexResponse createEmptyIndex(Client client, String indexName) {
ImmutableSettings.Builder builder = ImmutableSettings.builder();
Settings settings = builder.build();
return client.admin().indices().create(new CreateIndexRequest(indexName, settings)).actionGet();
}
public static PutMappingResponse createMapping(Client client, String indexName, String typeName, XContentBuilder mapping) {
PutMappingRequest putMappingRequest = new PutMappingRequest().indices(new String[] {indexName}).type(typeName).source(mapping);
return client.admin().indices().putMapping(putMappingRequest).actionGet();
}
public static boolean hasType(Client client, String indexName, String indexType) {
return client.admin().indices().typesExists(new TypesExistsRequest(new String[]{indexName}, indexType)).actionGet().isExists();
}
public static boolean hasIndex(Client client, String indexName) {
return client.admin().indices().exists(new IndicesExistsRequest(indexName)).actionGet().isExists();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy