Search in sources :

Example 6 with IndexSettings

use of com.enonic.xp.repository.IndexSettings in project xp by enonic.

the class NodeRepositoryServiceImpl method getDefaultSettings.

private IndexSettings getDefaultSettings(final RepositoryId repositoryId, final IndexType indexType) {
    final IndexSettings defaultSettings = DEFAULT_INDEX_RESOURCE_PROVIDER.getSettings(repositoryId, indexType);
    if (SystemConstants.SYSTEM_REPO_ID.equals(repositoryId)) {
        return defaultSettings;
    }
    try {
        final String numberOfReplicasString = indexServiceInternal.getIndexSettings(SystemConstants.SYSTEM_REPO_ID, IndexType.VERSION).getNode().get("index.number_of_replicas").textValue();
        final int numberOfReplicas = Integer.parseInt(numberOfReplicasString);
        final ObjectNode indexNodeObject = (ObjectNode) defaultSettings.getNode().get("index");
        indexNodeObject.put("number_of_replicas", numberOfReplicas);
    } catch (Exception e) {
        LOG.warn("Failed to retrieve number of replicas from [" + IndexNameResolver.resolveStorageIndexName(SystemConstants.SYSTEM_REPO_ID) + "]");
    }
    return defaultSettings;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IndexSettings(com.enonic.xp.repository.IndexSettings)

Example 7 with IndexSettings

use of com.enonic.xp.repository.IndexSettings in project xp by enonic.

the class IndexServiceImplTest method getIndexSettings.

@Test
public void getIndexSettings() throws Exception {
    this.indexService.updateIndexSettings(UpdateIndexSettingsParams.create().repository(TEST_REPO_ID).settings("{\"index\": {\"number_of_replicas\": 2}}").build());
    final IndexSettings indexSettings = this.indexService.getIndexSettings(TEST_REPO_ID, IndexType.SEARCH);
    assertEquals("\"2\"", indexSettings.getNode().get("index.number_of_replicas").toString());
}
Also used : IndexSettings(com.enonic.xp.repository.IndexSettings) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 8 with IndexSettings

use of com.enonic.xp.repository.IndexSettings in project xp by enonic.

the class IndexServiceImplTest method getIndexSettings_empty.

@Test
public void getIndexSettings_empty() throws Exception {
    final IndexSettings indexSettings = this.indexService.getIndexSettings(TEST_REPO_ID, IndexType.SEARCH);
    assertNull(indexSettings.getNode().get("index.invalid_path"));
}
Also used : IndexSettings(com.enonic.xp.repository.IndexSettings) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 9 with IndexSettings

use of com.enonic.xp.repository.IndexSettings in project xp by enonic.

the class IndexServiceInternalImpl method createIndex.

@Override
public void createIndex(final com.enonic.xp.repo.impl.index.CreateIndexRequest request) {
    final String indexName = request.getIndexName();
    final IndexSettings indexSettings = request.getIndexSettings();
    LOG.info("creating index {}", indexName);
    CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName);
    createIndexRequest.settings(indexSettings.getAsString());
    if (request.getMappings() != null) {
        for (Map.Entry<IndexType, IndexMapping> mappingEntry : request.getMappings().entrySet()) {
            createIndexRequest.mapping(mappingEntry.getKey().isDynamicTypes() ? ES_DEFAULT_INDEX_TYPE_NAME : mappingEntry.getKey().getName(), mappingEntry.getValue().getAsString());
        }
    }
    try {
        final CreateIndexResponse createIndexResponse = client.admin().indices().create(createIndexRequest).actionGet(CREATE_INDEX_TIMEOUT);
        LOG.info("Index {} created with status {}", indexName, createIndexResponse.isAcknowledged());
    } catch (ElasticsearchException e) {
        throw new IndexException("Failed to create index: " + indexName, e);
    }
}
Also used : IndexMapping(com.enonic.xp.repository.IndexMapping) IndexException(com.enonic.xp.repository.IndexException) UpdateIndexSettings(com.enonic.xp.repo.impl.index.UpdateIndexSettings) IndexSettings(com.enonic.xp.repository.IndexSettings) ElasticsearchException(org.elasticsearch.ElasticsearchException) CreateIndexRequest(org.elasticsearch.action.admin.indices.create.CreateIndexRequest) IndexType(com.enonic.xp.index.IndexType) CreateIndexResponse(org.elasticsearch.action.admin.indices.create.CreateIndexResponse) ImmutableOpenMap(org.elasticsearch.common.collect.ImmutableOpenMap) Map(java.util.Map)

Example 10 with IndexSettings

use of com.enonic.xp.repository.IndexSettings in project xp by enonic.

the class IndexServiceImpl method getSearchIndexSettings.

private IndexSettings getSearchIndexSettings(final RepositoryId repositoryId) {
    final IndexSettings defaultIndexSettings = DEFAULT_INDEX_RESOURCE_PROVIDER.getSettings(repositoryId, IndexType.SEARCH);
    final Repository repositoryEntry = repositoryEntryService.getRepositoryEntry(repositoryId);
    if (repositoryEntry != null) {
        final IndexSettings indexSettings = repositoryEntry.getSettings().getIndexSettings(IndexType.SEARCH);
        if (indexSettings != null) {
            return new IndexSettings(JsonHelper.merge(defaultIndexSettings.getNode(), indexSettings.getNode()));
        }
    }
    return defaultIndexSettings;
}
Also used : Repository(com.enonic.xp.repository.Repository) IndexSettings(com.enonic.xp.repository.IndexSettings)

Aggregations

IndexSettings (com.enonic.xp.repository.IndexSettings)11 IndexMapping (com.enonic.xp.repository.IndexMapping)4 IndexType (com.enonic.xp.index.IndexType)3 AbstractNodeTest (com.enonic.xp.repo.impl.node.AbstractNodeTest)2 IndexDefinition (com.enonic.xp.repository.IndexDefinition)2 Map (java.util.Map)2 Test (org.junit.jupiter.api.Test)2 PropertySet (com.enonic.xp.data.PropertySet)1 UpdateIndexSettings (com.enonic.xp.repo.impl.index.UpdateIndexSettings)1 IndexDefinitions (com.enonic.xp.repository.IndexDefinitions)1 IndexException (com.enonic.xp.repository.IndexException)1 Repository (com.enonic.xp.repository.Repository)1 RepositoryId (com.enonic.xp.repository.RepositoryId)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)1 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)1 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)1