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;
}
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");
}
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));
}
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);
}
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));
}
Aggregations