Search in sources :

Example 1 with IndexMapping

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

the class CreateRepositoryHandler method setIndexDefinitions.

public void setIndexDefinitions(final ScriptValue data) {
    if (data != null) {
        final Map<String, Object> indexDefinitionsMap = data.getMap();
        final IndexDefinitions.Builder indexDefinitionsBuilder = IndexDefinitions.create();
        for (IndexType indexType : IndexType.values()) {
            final Map indexDefinitionMap = (Map) indexDefinitionsMap.get(indexType.getName());
            if (indexDefinitionMap != null) {
                final Map indexDefinitionSettingsMap = (Map) indexDefinitionMap.get("settings");
                IndexSettings indexSettings = indexDefinitionSettingsMap == null ? null : new IndexSettings(createJson(indexDefinitionSettingsMap));
                final Map indexDefinitionMappingMap = (Map) indexDefinitionMap.get("mapping");
                IndexMapping indexMapping = indexDefinitionMappingMap == null ? null : new IndexMapping(createJson(indexDefinitionMappingMap));
                final IndexDefinition indexDefinition = IndexDefinition.create().settings(indexSettings).mapping(indexMapping).build();
                indexDefinitionsBuilder.add(indexType, indexDefinition);
            }
        }
        this.indexDefinitions = indexDefinitionsBuilder.build();
    }
}
Also used : IndexMapping(com.enonic.xp.repository.IndexMapping) IndexDefinition(com.enonic.xp.repository.IndexDefinition) IndexSettings(com.enonic.xp.repository.IndexSettings) IndexType(com.enonic.xp.index.IndexType) Map(java.util.Map) IndexDefinitions(com.enonic.xp.repository.IndexDefinitions)

Example 2 with IndexMapping

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

the class IndexServiceImpl method doPurgeSearchIndex.

private void doPurgeSearchIndex(final RepositoryId repositoryId) {
    final String searchIndexName = IndexNameResolver.resolveSearchIndexName(repositoryId);
    indexServiceInternal.deleteIndices(searchIndexName);
    final IndexSettings indexSettings = getSearchIndexSettings(repositoryId);
    final IndexMapping indexMapping = getSearchIndexMapping(repositoryId);
    indexServiceInternal.createIndex(CreateIndexRequest.create().indexName(searchIndexName).indexSettings(indexSettings).mappings(Map.of(IndexType.SEARCH, indexMapping)).build());
    indexServiceInternal.waitForYellowStatus(searchIndexName);
}
Also used : IndexMapping(com.enonic.xp.repository.IndexMapping) IndexSettings(com.enonic.xp.repository.IndexSettings)

Example 3 with IndexMapping

use of com.enonic.xp.repository.IndexMapping 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 4 with IndexMapping

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

the class IndexServiceImpl method getSearchIndexMapping.

private IndexMapping getSearchIndexMapping(final RepositoryId repositoryId) {
    final IndexMapping defaultIndexMapping = DEFAULT_INDEX_RESOURCE_PROVIDER.getMapping(repositoryId, IndexType.SEARCH);
    final Repository repositoryEntry = repositoryEntryService.getRepositoryEntry(repositoryId);
    if (repositoryEntry != null) {
        final IndexMapping indexMapping = repositoryEntry.getSettings().getIndexMappings(IndexType.SEARCH);
        if (indexMapping != null) {
            return new IndexMapping(JsonHelper.merge(defaultIndexMapping.getNode(), indexMapping.getNode()));
        }
    }
    return defaultIndexMapping;
}
Also used : IndexMapping(com.enonic.xp.repository.IndexMapping) Repository(com.enonic.xp.repository.Repository)

Example 5 with IndexMapping

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

the class RepositoryNodeTranslator method toNodeData.

private static void toNodeData(final IndexDefinitions indexDefinitions, final PropertyTree data) {
    if (indexDefinitions != null) {
        final PropertySet indexConfigsPropertySet = data.addSet(INDEX_CONFIG_KEY);
        for (IndexType indexType : IndexType.values()) {
            final IndexDefinition indexDefinition = indexDefinitions.get(indexType);
            if (indexDefinition != null) {
                final PropertySet indexConfigPropertySet = indexConfigsPropertySet.addSet(indexType.getName());
                final IndexMapping indexMapping = indexDefinition.getMapping();
                if (indexMapping != null) {
                    final PropertySet indexMappingPropertySet = JsonToPropertyTreeTranslator.translate(indexMapping.getNode()).getRoot();
                    indexConfigPropertySet.setSet(MAPPING_KEY, indexMappingPropertySet);
                }
                final IndexSettings indexSettings = indexDefinition.getSettings();
                if (indexSettings != null) {
                    final PropertySet indexSettingsPropertySet = JsonToPropertyTreeTranslator.translate(indexSettings.getNode()).getRoot();
                    indexConfigPropertySet.setSet(SETTINGS_KEY, indexSettingsPropertySet);
                }
            }
        }
    }
}
Also used : IndexMapping(com.enonic.xp.repository.IndexMapping) IndexDefinition(com.enonic.xp.repository.IndexDefinition) IndexSettings(com.enonic.xp.repository.IndexSettings) PropertySet(com.enonic.xp.data.PropertySet) IndexType(com.enonic.xp.index.IndexType)

Aggregations

IndexMapping (com.enonic.xp.repository.IndexMapping)6 IndexSettings (com.enonic.xp.repository.IndexSettings)4 IndexType (com.enonic.xp.index.IndexType)3 IndexDefinition (com.enonic.xp.repository.IndexDefinition)2 Map (java.util.Map)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 JsonNode (com.fasterxml.jackson.databind.JsonNode)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