diff --git a/graylog2-server/src/main/java/org/graylog2/indexer/IndexMapping.java b/graylog2-server/src/main/java/org/graylog2/indexer/IndexMapping.java index ced8ccd6cb44..f5073b9b56d4 100644 --- a/graylog2-server/src/main/java/org/graylog2/indexer/IndexMapping.java +++ b/graylog2-server/src/main/java/org/graylog2/indexer/IndexMapping.java @@ -18,21 +18,13 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import org.elasticsearch.action.ActionFuture; -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.graylog2.indexer.ranges.IndexRange; import org.graylog2.plugin.Tools; -import javax.inject.Inject; import javax.inject.Singleton; import java.io.Serializable; import java.util.List; import java.util.Map; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Representing the message type mapping in ElasticSearch. This is giving ES more * information about what the fields look like and how it should analyze them. @@ -41,24 +33,6 @@ public class IndexMapping { public static final String TYPE_MESSAGE = "message"; - private final Client client; - - @Inject - public IndexMapping(Client client) { - this.client = checkNotNull(client); - } - - public ActionFuture createMapping(final String index, final String type, final Map mapping) { - return client.admin().indices().putMapping(mappingRequest(index, type, mapping)); - } - - private PutMappingRequest mappingRequest(final String index, final String type, final Map mapping) { - return client.admin().indices().preparePutMapping(index) - .setType(type) - .setSource(ImmutableMap.of(type, mapping)) - .request(); - } - public Map messageMapping(final String analyzer) { return ImmutableMap.of( "properties", partFieldProperties(analyzer), diff --git a/graylog2-server/src/main/java/org/graylog2/indexer/indices/Indices.java b/graylog2-server/src/main/java/org/graylog2/indexer/indices/Indices.java index a53a5dc05ed9..9ce1cef6d32c 100644 --- a/graylog2-server/src/main/java/org/graylog2/indexer/indices/Indices.java +++ b/graylog2-server/src/main/java/org/graylog2/indexer/indices/Indices.java @@ -37,7 +37,6 @@ import org.elasticsearch.action.admin.indices.flush.FlushRequest; import org.elasticsearch.action.admin.indices.get.GetIndexRequest; import org.elasticsearch.action.admin.indices.get.GetIndexResponse; -import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse; import org.elasticsearch.action.admin.indices.open.OpenIndexRequest; import org.elasticsearch.action.admin.indices.optimize.OptimizeRequest; import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; @@ -220,17 +219,14 @@ public boolean create(String indexName) { "number_of_shards", configuration.getShards(), "number_of_replicas", configuration.getReplicas(), "index.analysis.analyzer.analyzer_keyword", keywordLowercase); - - final CreateIndexRequest cir = c.admin().indices().prepareCreate(indexName).setSettings(settings).request(); - if (!c.admin().indices().create(cir).actionGet().isAcknowledged()) { - return false; - } - final Map messageMapping = indexMapping.messageMapping(configuration.getAnalyzer()); - final PutMappingResponse messageMappingResponse = - indexMapping.createMapping(indexName, IndexMapping.TYPE_MESSAGE, messageMapping).actionGet(); - return messageMappingResponse.isAcknowledged(); + final CreateIndexRequest cir = c.admin().indices().prepareCreate(indexName) + .setSettings(settings) + .addMapping(IndexMapping.TYPE_MESSAGE, messageMapping) + .request(); + + return c.admin().indices().create(cir).actionGet().isAcknowledged(); } public Set getAllMessageFields() { diff --git a/graylog2-server/src/test/java/org/graylog2/indexer/indices/IndicesTest.java b/graylog2-server/src/test/java/org/graylog2/indexer/indices/IndicesTest.java index dbdb38c051ee..a5a3ec2c3307 100644 --- a/graylog2-server/src/test/java/org/graylog2/indexer/indices/IndicesTest.java +++ b/graylog2-server/src/test/java/org/graylog2/indexer/indices/IndicesTest.java @@ -78,7 +78,7 @@ public IndicesTest() { @Before public void setUp() throws Exception { - indices = new Indices(client, CONFIG, new IndexMapping(client)); + indices = new Indices(client, CONFIG, new IndexMapping()); } @Test diff --git a/graylog2-server/src/test/java/org/graylog2/indexer/nosqlunit/IndexCreatingDatabaseOperation.java b/graylog2-server/src/test/java/org/graylog2/indexer/nosqlunit/IndexCreatingDatabaseOperation.java index af1f8ace5d38..1a440f3e69a8 100644 --- a/graylog2-server/src/test/java/org/graylog2/indexer/nosqlunit/IndexCreatingDatabaseOperation.java +++ b/graylog2-server/src/test/java/org/graylog2/indexer/nosqlunit/IndexCreatingDatabaseOperation.java @@ -51,7 +51,7 @@ public void insert(InputStream dataScript) { client.admin().indices().prepareDelete(index).execute().actionGet(); } - Indices indices = new Indices(client, new ElasticsearchConfiguration(), new IndexMapping(client)); + Indices indices = new Indices(client, new ElasticsearchConfiguration(), new IndexMapping()); if (!indices.create(index)) { throw new IllegalStateException("Couldn't create index " + index); } diff --git a/graylog2-server/src/test/java/org/graylog2/indexer/ranges/EsIndexRangeServiceTest.java b/graylog2-server/src/test/java/org/graylog2/indexer/ranges/EsIndexRangeServiceTest.java index 4eea7eca1329..0e61bebb2781 100644 --- a/graylog2-server/src/test/java/org/graylog2/indexer/ranges/EsIndexRangeServiceTest.java +++ b/graylog2-server/src/test/java/org/graylog2/indexer/ranges/EsIndexRangeServiceTest.java @@ -85,7 +85,7 @@ public EsIndexRangeServiceTest() { @Before public void setUp() throws Exception { - indices = new Indices(client, ELASTICSEARCH_CONFIGURATION, new IndexMapping(client)); + indices = new Indices(client, ELASTICSEARCH_CONFIGURATION, new IndexMapping()); final Deflector deflector = new Deflector(null, ELASTICSEARCH_CONFIGURATION, new NullActivityWriter(), null, null, indices); indexRangeService = new EsIndexRangeService(client, deflector, indices, localEventBus, clusterEventBus, new MetricRegistry()); }