use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project elasticsearch by elastic.
the class MultiFieldsIntegrationIT method testMultiFields.
public void testMultiFields() throws Exception {
assertAcked(client().admin().indices().prepareCreate("my-index").addMapping("my-type", createTypeSource()));
GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get();
MappingMetaData mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type");
assertThat(mappingMetaData, not(nullValue()));
Map<String, Object> mappingSource = mappingMetaData.sourceAsMap();
Map titleFields = ((Map) XContentMapValues.extractValue("properties.title.fields", mappingSource));
assertThat(titleFields.size(), equalTo(1));
assertThat(titleFields.get("not_analyzed"), notNullValue());
assertThat(((Map) titleFields.get("not_analyzed")).get("type").toString(), equalTo("keyword"));
client().prepareIndex("my-index", "my-type", "1").setSource("title", "Multi fields").setRefreshPolicy(IMMEDIATE).get();
SearchResponse searchResponse = client().prepareSearch("my-index").setQuery(matchQuery("title", "multi")).get();
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
searchResponse = client().prepareSearch("my-index").setQuery(matchQuery("title.not_analyzed", "Multi fields")).get();
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
assertAcked(client().admin().indices().preparePutMapping("my-index").setType("my-type").setSource(createPutMappingSource()));
getMappingsResponse = client().admin().indices().prepareGetMappings("my-index").get();
mappingMetaData = getMappingsResponse.mappings().get("my-index").get("my-type");
assertThat(mappingMetaData, not(nullValue()));
mappingSource = mappingMetaData.sourceAsMap();
assertThat(((Map) XContentMapValues.extractValue("properties.title", mappingSource)).size(), equalTo(2));
titleFields = ((Map) XContentMapValues.extractValue("properties.title.fields", mappingSource));
assertThat(titleFields.size(), equalTo(2));
assertThat(titleFields.get("not_analyzed"), notNullValue());
assertThat(((Map) titleFields.get("not_analyzed")).get("type").toString(), equalTo("keyword"));
assertThat(titleFields.get("uncased"), notNullValue());
assertThat(((Map) titleFields.get("uncased")).get("analyzer").toString(), equalTo("whitespace"));
client().prepareIndex("my-index", "my-type", "1").setSource("title", "Multi fields").setRefreshPolicy(IMMEDIATE).get();
searchResponse = client().prepareSearch("my-index").setQuery(matchQuery("title.uncased", "Multi")).get();
assertThat(searchResponse.getHits().getTotalHits(), equalTo(1L));
}
use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project elasticsearch by elastic.
the class UpdateMappingIntegrationIT method testUpdateMappingWithoutTypeMultiObjects.
public void testUpdateMappingWithoutTypeMultiObjects() throws Exception {
client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0)).execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("doc").setSource("{\"properties\":{\"date\":{\"type\":\"integer\"}}}", XContentType.JSON).execute().actionGet();
assertThat(putMappingResponse.isAcknowledged(), equalTo(true));
GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").execute().actionGet();
assertThat(getMappingsResponse.mappings().get("test").get("doc").source().toString(), equalTo("{\"doc\":{\"properties\":{\"date\":{\"type\":\"integer\"}}}}"));
}
use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project elasticsearch by elastic.
the class SimpleGetMappingsIT method testSimpleGetMappings.
public void testSimpleGetMappings() throws Exception {
client().admin().indices().prepareCreate("indexa").addMapping("typeA", getMappingForType("typeA")).addMapping("typeB", getMappingForType("typeB")).addMapping("Atype", getMappingForType("Atype")).addMapping("Btype", getMappingForType("Btype")).execute().actionGet();
client().admin().indices().prepareCreate("indexb").addMapping("typeA", getMappingForType("typeA")).addMapping("typeB", getMappingForType("typeB")).addMapping("Atype", getMappingForType("Atype")).addMapping("Btype", getMappingForType("Btype")).execute().actionGet();
ClusterHealthResponse clusterHealth = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
assertThat(clusterHealth.isTimedOut(), equalTo(false));
// Get all mappings
GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet();
assertThat(response.mappings().size(), equalTo(2));
assertThat(response.mappings().get("indexa").size(), equalTo(4));
assertThat(response.mappings().get("indexa").get("typeA"), notNullValue());
assertThat(response.mappings().get("indexa").get("typeB"), notNullValue());
assertThat(response.mappings().get("indexa").get("Atype"), notNullValue());
assertThat(response.mappings().get("indexa").get("Btype"), notNullValue());
assertThat(response.mappings().get("indexb").size(), equalTo(4));
assertThat(response.mappings().get("indexb").get("typeA"), notNullValue());
assertThat(response.mappings().get("indexb").get("typeB"), notNullValue());
assertThat(response.mappings().get("indexb").get("Atype"), notNullValue());
assertThat(response.mappings().get("indexb").get("Btype"), notNullValue());
// Get all mappings, via wildcard support
response = client().admin().indices().prepareGetMappings("*").setTypes("*").execute().actionGet();
assertThat(response.mappings().size(), equalTo(2));
assertThat(response.mappings().get("indexa").size(), equalTo(4));
assertThat(response.mappings().get("indexa").get("typeA"), notNullValue());
assertThat(response.mappings().get("indexa").get("typeB"), notNullValue());
assertThat(response.mappings().get("indexa").get("Atype"), notNullValue());
assertThat(response.mappings().get("indexa").get("Btype"), notNullValue());
assertThat(response.mappings().get("indexb").size(), equalTo(4));
assertThat(response.mappings().get("indexb").get("typeA"), notNullValue());
assertThat(response.mappings().get("indexb").get("typeB"), notNullValue());
assertThat(response.mappings().get("indexb").get("Atype"), notNullValue());
assertThat(response.mappings().get("indexb").get("Btype"), notNullValue());
// Get all typeA mappings in all indices
response = client().admin().indices().prepareGetMappings("*").setTypes("typeA").execute().actionGet();
assertThat(response.mappings().size(), equalTo(2));
assertThat(response.mappings().get("indexa").size(), equalTo(1));
assertThat(response.mappings().get("indexa").get("typeA"), notNullValue());
assertThat(response.mappings().get("indexb").size(), equalTo(1));
assertThat(response.mappings().get("indexb").get("typeA"), notNullValue());
// Get all mappings in indexa
response = client().admin().indices().prepareGetMappings("indexa").execute().actionGet();
assertThat(response.mappings().size(), equalTo(1));
assertThat(response.mappings().get("indexa").size(), equalTo(4));
assertThat(response.mappings().get("indexa").get("typeA"), notNullValue());
assertThat(response.mappings().get("indexa").get("typeB"), notNullValue());
assertThat(response.mappings().get("indexa").get("Atype"), notNullValue());
assertThat(response.mappings().get("indexa").get("Btype"), notNullValue());
// Get all mappings beginning with A* in indexa
response = client().admin().indices().prepareGetMappings("indexa").setTypes("A*").execute().actionGet();
assertThat(response.mappings().size(), equalTo(1));
assertThat(response.mappings().get("indexa").size(), equalTo(1));
assertThat(response.mappings().get("indexa").get("Atype"), notNullValue());
// Get all mappings beginning with B* in all indices
response = client().admin().indices().prepareGetMappings().setTypes("B*").execute().actionGet();
assertThat(response.mappings().size(), equalTo(2));
assertThat(response.mappings().get("indexa").size(), equalTo(1));
assertThat(response.mappings().get("indexa").get("Btype"), notNullValue());
assertThat(response.mappings().get("indexb").size(), equalTo(1));
assertThat(response.mappings().get("indexb").get("Btype"), notNullValue());
// Get all mappings beginning with B* and A* in all indices
response = client().admin().indices().prepareGetMappings().setTypes("B*", "A*").execute().actionGet();
assertThat(response.mappings().size(), equalTo(2));
assertThat(response.mappings().get("indexa").size(), equalTo(2));
assertThat(response.mappings().get("indexa").get("Atype"), notNullValue());
assertThat(response.mappings().get("indexa").get("Btype"), notNullValue());
assertThat(response.mappings().get("indexb").size(), equalTo(2));
assertThat(response.mappings().get("indexb").get("Atype"), notNullValue());
assertThat(response.mappings().get("indexb").get("Btype"), notNullValue());
}
use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project elasticsearch by elastic.
the class SimpleGetMappingsIT method testGetMappingsWhereThereAreNone.
public void testGetMappingsWhereThereAreNone() {
createIndex("index");
GetMappingsResponse response = client().admin().indices().prepareGetMappings().execute().actionGet();
assertThat(response.mappings().containsKey("index"), equalTo(true));
assertThat(response.mappings().get("index").size(), equalTo(0));
}
use of org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse in project elasticsearch by elastic.
the class ChildQuerySearchIT method testAddingParentToExistingMapping.
public void testAddingParentToExistingMapping() throws IOException {
createIndex("test");
ensureGreen();
PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("child").setSource("number", "type=integer").get();
assertThat(putMappingResponse.isAcknowledged(), equalTo(true));
GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("test").get();
Map<String, Object> mapping = getMappingsResponse.getMappings().get("test").get("child").getSourceAsMap();
// there are potentially some meta fields configured randomly
assertThat(mapping.size(), greaterThanOrEqualTo(1));
assertThat(mapping.get("properties"), notNullValue());
try {
// Adding _parent metadata field to existing mapping is prohibited:
client().admin().indices().preparePutMapping("test").setType("child").setSource(jsonBuilder().startObject().startObject("child").startObject("_parent").field("type", "parent").endObject().endObject().endObject()).get();
fail();
} catch (IllegalArgumentException e) {
assertThat(e.toString(), containsString("The _parent field's type option can't be changed: [null]->[parent]"));
}
}
Aggregations