Search in sources :

Example 11 with PutMappingResponse

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

the class AlterTableOperation method updateMapping.

private CompletableFuture<Long> updateMapping(Map<String, Object> newMapping, String... indices) {
    if (newMapping.isEmpty()) {
        return CompletableFuture.completedFuture(null);
    }
    assert areAllMappingsEqual(clusterService.state().metaData(), indices) : "Trying to update mapping for indices with different existing mappings";
    Map<String, Object> mapping;
    try {
        MetaData metaData = clusterService.state().metaData();
        String index = indices[0];
        mapping = metaData.index(index).mapping(Constants.DEFAULT_MAPPING_TYPE).getSourceAsMap();
    } catch (IOException e) {
        return CompletableFutures.failedFuture(e);
    }
    XContentHelper.update(mapping, newMapping, false);
    // update mapping of all indices
    PutMappingRequest request = new PutMappingRequest(indices);
    request.indicesOptions(IndicesOptions.lenientExpandOpen());
    request.type(Constants.DEFAULT_MAPPING_TYPE);
    request.source(mapping);
    FutureActionListener<PutMappingResponse, Long> listener = new FutureActionListener<>(LONG_NULL_FUNCTION);
    transportActionProvider.transportPutMappingAction().execute(request, listener);
    return listener;
}
Also used : PutMappingRequest(org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest) MetaData(org.elasticsearch.cluster.metadata.MetaData) AliasMetaData(org.elasticsearch.cluster.metadata.AliasMetaData) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) IOException(java.io.IOException) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) FutureActionListener(io.crate.action.FutureActionListener)

Example 12 with PutMappingResponse

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

the class CompletionSuggestSearchIT method testThatUpgradeToMultiFieldsWorks.

public void testThatUpgradeToMultiFieldsWorks() throws Exception {
    final XContentBuilder mapping = jsonBuilder().startObject().startObject(TYPE).startObject("properties").startObject(FIELD).field("type", "text").endObject().endObject().endObject().endObject();
    assertAcked(prepareCreate(INDEX).addMapping(TYPE, mapping));
    client().prepareIndex(INDEX, TYPE, "1").setRefreshPolicy(IMMEDIATE).setSource(jsonBuilder().startObject().field(FIELD, "Foo Fighters").endObject()).get();
    ensureGreen(INDEX);
    PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(jsonBuilder().startObject().startObject(TYPE).startObject("properties").startObject(FIELD).field("type", "text").startObject("fields").startObject("suggest").field("type", "completion").field("analyzer", "simple").endObject().endObject().endObject().endObject().endObject().endObject()).get();
    assertThat(putMappingResponse.isAcknowledged(), is(true));
    SearchResponse searchResponse = client().prepareSearch(INDEX).suggest(new SuggestBuilder().addSuggestion("suggs", SuggestBuilders.completionSuggestion(FIELD + ".suggest").text("f").size(10))).execute().actionGet();
    assertSuggestions(searchResponse, "suggs");
    client().prepareIndex(INDEX, TYPE, "1").setRefreshPolicy(IMMEDIATE).setSource(jsonBuilder().startObject().field(FIELD, "Foo Fighters").endObject()).get();
    ensureGreen(INDEX);
    SearchResponse afterReindexingResponse = client().prepareSearch(INDEX).suggest(new SuggestBuilder().addSuggestion("suggs", SuggestBuilders.completionSuggestion(FIELD + ".suggest").text("f").size(10))).execute().actionGet();
    assertSuggestions(afterReindexingResponse, "suggs", "Foo Fighters");
}
Also used : PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 13 with PutMappingResponse

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

the class CompletionSuggestSearchIT method testThatStatsAreWorking.

public void testThatStatsAreWorking() throws Exception {
    String otherField = "testOtherField";
    client().admin().indices().prepareCreate(INDEX).setSettings(Settings.builder().put("index.number_of_replicas", 0).put("index.number_of_shards", 2)).execute().actionGet();
    ensureGreen();
    PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(jsonBuilder().startObject().startObject(TYPE).startObject("properties").startObject(FIELD).field("type", "completion").field("analyzer", "simple").endObject().startObject(otherField).field("type", "completion").field("analyzer", "simple").endObject().endObject().endObject().endObject()).get();
    assertThat(putMappingResponse.isAcknowledged(), is(true));
    // Index two entities
    client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder().startObject().field(FIELD, "Foo Fighters").field(otherField, "WHATEVER").endObject()).get();
    client().prepareIndex(INDEX, TYPE, "2").setSource(jsonBuilder().startObject().field(FIELD, "Bar Fighters").field(otherField, "WHATEVER2").endObject()).get();
    refresh();
    ensureGreen();
    // load the fst index into ram
    client().prepareSearch(INDEX).suggest(new SuggestBuilder().addSuggestion("foo", SuggestBuilders.completionSuggestion(FIELD).prefix("f"))).get();
    client().prepareSearch(INDEX).suggest(new SuggestBuilder().addSuggestion("foo", SuggestBuilders.completionSuggestion(otherField).prefix("f"))).get();
    // Get all stats
    IndicesStatsResponse indicesStatsResponse = client().admin().indices().prepareStats(INDEX).setIndices(INDEX).setCompletion(true).get();
    CompletionStats completionStats = indicesStatsResponse.getIndex(INDEX).getPrimaries().completion;
    assertThat(completionStats, notNullValue());
    long totalSizeInBytes = completionStats.getSizeInBytes();
    assertThat(totalSizeInBytes, is(greaterThan(0L)));
    IndicesStatsResponse singleFieldStats = client().admin().indices().prepareStats(INDEX).setIndices(INDEX).setCompletion(true).setCompletionFields(FIELD).get();
    long singleFieldSizeInBytes = singleFieldStats.getIndex(INDEX).getPrimaries().completion.getFields().get(FIELD);
    IndicesStatsResponse otherFieldStats = client().admin().indices().prepareStats(INDEX).setIndices(INDEX).setCompletion(true).setCompletionFields(otherField).get();
    long otherFieldSizeInBytes = otherFieldStats.getIndex(INDEX).getPrimaries().completion.getFields().get(otherField);
    assertThat(singleFieldSizeInBytes + otherFieldSizeInBytes, is(totalSizeInBytes));
    // regexes
    IndicesStatsResponse regexFieldStats = client().admin().indices().prepareStats(INDEX).setIndices(INDEX).setCompletion(true).setCompletionFields("*").get();
    FieldMemoryStats fields = regexFieldStats.getIndex(INDEX).getPrimaries().completion.getFields();
    long regexSizeInBytes = fields.get(FIELD) + fields.get(otherField);
    assertThat(regexSizeInBytes, is(totalSizeInBytes));
}
Also used : IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) FieldMemoryStats(org.elasticsearch.common.FieldMemoryStats) Matchers.containsString(org.hamcrest.Matchers.containsString) PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) CompletionStats(org.elasticsearch.search.suggest.completion.CompletionStats)

Example 14 with PutMappingResponse

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

the class SizeMappingIT method testThatSizeCanBeSwitchedOnAndOff.

public void testThatSizeCanBeSwitchedOnAndOff() throws Exception {
    String index = "foo";
    String type = "mytype";
    XContentBuilder builder = jsonBuilder().startObject().startObject("_size").field("enabled", true).endObject().endObject();
    assertAcked(client().admin().indices().prepareCreate(index).addMapping(type, builder));
    // check mapping again
    assertSizeMappingEnabled(index, type, true);
    // update some field in the mapping
    XContentBuilder updateMappingBuilder = jsonBuilder().startObject().startObject("_size").field("enabled", false).endObject().endObject();
    PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping(index).setType(type).setSource(updateMappingBuilder).get();
    assertAcked(putMappingResponse);
    // make sure size field is still in mapping
    assertSizeMappingEnabled(index, type, false);
}
Also used : PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 15 with PutMappingResponse

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

the class AckIT method testPutMappingNoAcknowledgement.

public void testPutMappingNoAcknowledgement() {
    createIndex("test");
    ensureGreen();
    PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("test").setSource("field", "type=keyword").setTimeout("0s").get();
    assertThat(putMappingResponse.isAcknowledged(), equalTo(false));
}
Also used : PutMappingResponse(org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)

Aggregations

PutMappingResponse (org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)22 IOException (java.io.IOException)7 GetMappingsResponse (org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse)6 ClusterState (org.elasticsearch.cluster.ClusterState)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 MappingMetaData (org.elasticsearch.cluster.metadata.MappingMetaData)3 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)3 Map (java.util.Map)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)2 IndexResponse (org.elasticsearch.action.index.IndexResponse)2 ImmutableOpenMap (org.elasticsearch.common.collect.ImmutableOpenMap)2 Settings (org.elasticsearch.common.settings.Settings)2 Index (org.elasticsearch.index.Index)2 IndexService (org.elasticsearch.index.IndexService)2 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)2 MapperService (org.elasticsearch.index.mapper.MapperService)2 IndicesService (org.elasticsearch.indices.IndicesService)2