Search in sources :

Example 36 with PutMappingResponse

use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project elasticsearch-opennlp-plugin by spinscale.

the class OpenNlpPluginIntegrationTest method putMapping.

private void putMapping(String mappingFile) throws IOException {
    String mapping = copyToStringFromClasspath(mappingFile);
    PutMappingRequestBuilder putMappingRequestBuilder = new PutMappingRequestBuilder(node.client().admin().indices());
    PutMappingResponse putMappingResponse = putMappingRequestBuilder.setIndices(index).setType(type).setSource(mapping).execute().actionGet();
    assertThat(putMappingResponse.isAcknowledged(), is(true));
}
Also used : PutMappingRequestBuilder(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)

Example 37 with PutMappingResponse

use of org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse in project titan by thinkaurelius.

the class ElasticSearchIndex method register.

@Override
public void register(String store, String key, KeyInformation information, TransactionHandle tx) throws StorageException {
    XContentBuilder mapping = null;
    Class<?> dataType = information.getDataType();
    Mapping map = Mapping.getMapping(information);
    Preconditions.checkArgument(map == Mapping.DEFAULT || AttributeUtil.isString(dataType), "Specified illegal mapping [%s] for data type [%s]", map, dataType);
    try {
        mapping = XContentFactory.jsonBuilder().startObject().startObject(store).startObject("properties").startObject(key);
        if (AttributeUtil.isString(dataType)) {
            log.debug("Registering string type for {}", key);
            mapping.field("type", "string");
            if (map == Mapping.STRING)
                mapping.field("index", "not_analyzed");
        } else if (dataType == Float.class || dataType == FullFloat.class) {
            log.debug("Registering float type for {}", key);
            mapping.field("type", "float");
        } else if (dataType == Double.class || dataType == FullDouble.class) {
            log.debug("Registering double type for {}", key);
            mapping.field("type", "double");
        } else if (dataType == Byte.class) {
            log.debug("Registering byte type for {}", key);
            mapping.field("type", "byte");
        } else if (dataType == Short.class) {
            log.debug("Registering short type for {}", key);
            mapping.field("type", "short");
        } else if (dataType == Integer.class) {
            log.debug("Registering integer type for {}", key);
            mapping.field("type", "integer");
        } else if (dataType == Long.class) {
            log.debug("Registering long type for {}", key);
            mapping.field("type", "long");
        } else if (dataType == Boolean.class) {
            log.debug("Registering boolean type for {}", key);
            mapping.field("type", "boolean");
        } else if (dataType == Geoshape.class) {
            log.debug("Registering geo_point type for {}", key);
            mapping.field("type", "geo_point");
        }
        mapping.endObject().endObject().endObject().endObject();
    } catch (IOException e) {
        throw new PermanentStorageException("Could not render json for put mapping request", e);
    }
    try {
        PutMappingResponse response = client.admin().indices().preparePutMapping(indexName).setIgnoreConflicts(false).setType(store).setSource(mapping).execute().actionGet();
    } catch (Exception e) {
        throw convert(e);
    }
}
Also used : PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) Mapping(com.thinkaurelius.titan.core.Mapping) IOException(java.io.IOException) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) ElasticSearchInterruptedException(org.elasticsearch.ElasticSearchInterruptedException) PermanentStorageException(com.thinkaurelius.titan.diskstorage.PermanentStorageException) TitanException(com.thinkaurelius.titan.core.TitanException) TemporaryStorageException(com.thinkaurelius.titan.diskstorage.TemporaryStorageException) IndexMissingException(org.elasticsearch.indices.IndexMissingException) StorageException(com.thinkaurelius.titan.diskstorage.StorageException) IOException(java.io.IOException)

Aggregations

PutMappingResponse (org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)37 IOException (java.io.IOException)19 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)11 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)9 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)9 IndicesExistsRequest (org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest)9 GetMappingsResponse (org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)7 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)7 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)4 ClusterState (org.elasticsearch.cluster.ClusterState)4 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 ElasticsearchException (org.elasticsearch.ElasticsearchException)3 PutMappingRequest (org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest)3 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)3 TitanException (com.thinkaurelius.titan.core.TitanException)2 DtDefinition (io.vertigo.dynamo.domain.metamodel.DtDefinition)2 DtField (io.vertigo.dynamo.domain.metamodel.DtField)2 Map (java.util.Map)2