Skip to content

Commit

Permalink
The Setup API now creates .zentity-models as a hidden index.
Browse files Browse the repository at this point in the history
  • Loading branch information
davemoore- committed Oct 5, 2021
1 parent d9354aa commit f4b7127
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 27 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Expand Up @@ -22,8 +22,8 @@

<!-- Dependency versions -->
<elasticsearch.version>7.15.0</elasticsearch.version>
<jackson.core.version>2.10.5</jackson.core.version>
<jackson.databind.version>2.10.5.1</jackson.databind.version>
<jackson.core.version>2.12.5</jackson.core.version>
<jackson.databind.version>2.12.5</jackson.databind.version>
<jdk.version>1.11</jdk.version>
<log4j.version>2.11.1</log4j.version>
<commons-io.version>2.8.0</commons-io.version>
Expand Down Expand Up @@ -87,7 +87,7 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.15.1</version>
<version>1.16.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
32 changes: 8 additions & 24 deletions src/main/java/org/elasticsearch/plugin/zentity/SetupAction.java
Expand Up @@ -33,7 +33,6 @@
import org.elasticsearch.rest.RestStatus;

import java.util.List;
import java.util.Properties;

import static org.elasticsearch.rest.RestRequest.Method;
import static org.elasticsearch.rest.RestRequest.Method.POST;
Expand Down Expand Up @@ -65,9 +64,6 @@ public class SetupAction extends BaseRestHandler {
" }\n" +
" }\n" +
"}";
public static final String INDEX_MAPPING_ELASTICSEARCH_6 = "{\n" +
" \"doc\": " + INDEX_MAPPING + "\n" +
"}";

@Override
public List<Route> routes() {
Expand All @@ -83,28 +79,16 @@ public List<Route> routes() {
* @param numberOfShards The value of index.number_of_shards.
* @param numberOfReplicas The value of index.number_of_replicas.
* @param onComplete Action to perform after index creation request completes.
* @return
*/
public static void createIndex(NodeClient client, int numberOfShards, int numberOfReplicas, ActionListener<CreateIndexResponse> onComplete) {
// Elasticsearch 7.0.0+ removes mapping types
Properties props = ZentityPlugin.properties();
if (props.getProperty("elasticsearch.version").compareTo("7.") >= 0) {
client.admin().indices().prepareCreate(ModelsAction.INDEX_NAME)
.setSettings(Settings.builder()
.put("index.number_of_shards", numberOfShards)
.put("index.number_of_replicas", numberOfReplicas)
)
.addMapping("doc", INDEX_MAPPING, XContentType.JSON)
.execute(onComplete);
} else {
client.admin().indices().prepareCreate(ModelsAction.INDEX_NAME)
.setSettings(Settings.builder()
.put("index.number_of_shards", numberOfShards)
.put("index.number_of_replicas", numberOfReplicas)
)
.addMapping("doc", INDEX_MAPPING_ELASTICSEARCH_6, XContentType.JSON)
.execute(onComplete);
}
client.admin().indices().prepareCreate(ModelsAction.INDEX_NAME)
.setSettings(Settings.builder()
.put("index.hidden", true)
.put("index.number_of_shards", numberOfShards)
.put("index.number_of_replicas", numberOfReplicas)
)
.addMapping("doc", INDEX_MAPPING, XContentType.JSON)
.execute(onComplete);
}

/**
Expand Down

0 comments on commit f4b7127

Please sign in to comment.