Package org.elasticsearch.action.admin.indices.mapping.put

Examples of org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder


*/
@SuppressWarnings({"unchecked"})
public class Mapping {

    public static PutMappingRequest getPutMappingRequest(final Client client, final String index, final String analyzer) {
        final PutMappingRequestBuilder builder = client.admin().indices().preparePutMapping(new String[] {index});
        builder.setType(Messages.TYPE);

        final Map<String, Object> mapping = new HashMap<String, Object>();
        mapping.put("properties", partFieldProperties(analyzer));
        mapping.put("dynamic_templates", partDefaultAllInDynamicTemplate());
        mapping.put("_source", enabledAndCompressed()); // Compress source field..
        mapping.put("_ttl", enabled()); // Enable purging by TTL.

        // TODO: use multimap?
        final Map<String, Map<String, Object>> completeMapping = Maps.newHashMap();
        completeMapping.put(Messages.TYPE, mapping);

        builder.setSource(completeMapping);
        return builder.request();
    }
View Full Code Here


            // Wait for create to be finished.
            client.admin().indices().prepareRefresh(indexName).execute().actionGet();

            //Put the schema/mapping
            log.info("Put Mapping for ["+indexName+"]/["+indexType+"]="+stringMappingJSON);
            PutMappingRequestBuilder putMappingRequestBuilder = client.admin().indices().preparePutMapping(indexName).setType(indexType);
            putMappingRequestBuilder.setSource(stringMappingJSON);
            PutMappingResponse response = putMappingRequestBuilder.execute().actionGet();

            if(!response.isAcknowledged()) {
                log.info("Could not define mapping for type ["+indexName+"]/["+indexType+"]");
            } else {
                log.info("Successfully put mapping for ["+indexName+"]/["+indexType+"]");
View Full Code Here

    ListenableActionFuture<PutMappingResponse> future = _store
        .execute(new StoreOperation<ListenableActionFuture<PutMappingResponse>>() {

          @Override
          public ListenableActionFuture<PutMappingResponse> execute(Client client, String indexName) {
            PutMappingRequestBuilder request = client.admin().indices().preparePutMapping(indexName);
            request.setType(typeMapping.getTypeAlias());
            typeMapping.getMappingSource().setSource(request);
            return request.execute();
          }

        });

    // TODO handle response
View Full Code Here

  @Override
  public boolean putMapping(String indexName, String type, Object mapping) {
    Assert.notNull(indexName, "No index defined for putMapping()");
    Assert.notNull(type, "No type defined for putMapping()");
    PutMappingRequestBuilder requestBuilder = client.admin().indices()
        .preparePutMapping(indexName).setType(type);
    if (mapping instanceof String) {
      requestBuilder.setSource(String.valueOf(mapping));
    } else if (mapping instanceof Map) {
      requestBuilder.setSource((Map) mapping);
    } else if (mapping instanceof XContentBuilder) {
      requestBuilder.setSource((XContentBuilder) mapping);
    }
    return requestBuilder.execute().actionGet().isAcknowledged();
  }
View Full Code Here

  SearchClient searchClient = new SearchClient(new Settings(), profiling);

  @Test
  public void put_mapping() {
    try {
      PutMappingRequestBuilder requestBuilder = searchClient.preparePutMapping(IndexDefinition.RULE.getIndexName())
        .setType(IndexDefinition.RULE.getIndexType())
        .setIgnoreConflicts(true)
        .setSource(mapDomain());
      requestBuilder.get();

      // expected to fail because elasticsearch is not correctly configured, but that does not matter
      fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(IllegalStateException.class);
View Full Code Here

  public void with_profiling_basic() {
    Profiling profiling = new Profiling(new Settings().setProperty(Profiling.CONFIG_PROFILING_LEVEL, Profiling.Level.BASIC.name()));
    SearchClient searchClient = new SearchClient(new Settings(), profiling);

    try {
      PutMappingRequestBuilder requestBuilder = searchClient.preparePutMapping(IndexDefinition.RULE.getIndexName())
        .setType(IndexDefinition.RULE.getIndexType())
        .setIgnoreConflicts(true)
        .setSource(mapDomain());
      requestBuilder.get();

      // expected to fail because elasticsearch is not correctly configured, but that does not matter
      fail();
    } catch (Exception e) {
      assertThat(e).isInstanceOf(IllegalStateException.class);
View Full Code Here

        execute(PutMappingAction.INSTANCE, request, listener);
    }

    @Override
    public PutMappingRequestBuilder preparePutMapping(String... indices) {
        return new PutMappingRequestBuilder(this).setIndices(indices);
    }
View Full Code Here

    }

    @Override
    public <T> boolean putMapping(Class<T> clazz) {
        ElasticsearchPersistentEntity<T> persistentEntity = getPersistentEntityFor(clazz);
        PutMappingRequestBuilder requestBuilder = client.admin().indices().preparePutMapping(persistentEntity.getIndexName())
                .setType(persistentEntity.getIndexType());

        try {
            XContentBuilder xContentBuilder = buildMapping(clazz, persistentEntity.getIndexType(), persistentEntity.getIdProperty().getFieldName());
            return requestBuilder.setSource(xContentBuilder).execute().actionGet().acknowledged();
        } catch (Exception e) {
            throw new ElasticsearchException("Failed to build mapping for " + clazz.getSimpleName() , e);
        }
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.