use of org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse in project pyramid by cheng-li.
the class ESIndex method getFieldType.
public String getFieldType(String field) {
GetFieldMappingsResponse response = this.client.admin().indices().prepareGetFieldMappings(this.indexName).setTypes(this.documentType).setFields(field).execute().actionGet();
Map map = (Map) response.mappings().get(this.indexName).get(this.documentType).get(field).sourceAsMap().get(field);
return map.get("type").toString();
}
use of org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse in project elasticsearch by elastic.
the class SimpleGetFieldMappingsIT method testGetMappingsWhereThereAreNone.
public void testGetMappingsWhereThereAreNone() {
createIndex("index");
GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings().get();
assertThat(response.mappings().size(), equalTo(1));
assertThat(response.mappings().get("index").size(), equalTo(0));
assertThat(response.fieldMappings("index", "type", "field"), Matchers.nullValue());
}
use of org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse in project elasticsearch by elastic.
the class SimpleGetFieldMappingsIT method testSimpleGetFieldMappingsWithPretty.
//fix #6552
public void testSimpleGetFieldMappingsWithPretty() throws Exception {
assertAcked(prepareCreate("index").addMapping("type", getMappingForType("type")));
Map<String, String> params = new HashMap<>();
params.put("pretty", "true");
GetFieldMappingsResponse response = client().admin().indices().prepareGetFieldMappings("index").setTypes("type").setFields("field1", "obj.subfield").get();
XContentBuilder responseBuilder = XContentFactory.jsonBuilder().prettyPrint();
responseBuilder.startObject();
response.toXContent(responseBuilder, new ToXContent.MapParams(params));
responseBuilder.endObject();
String responseStrings = responseBuilder.string();
XContentBuilder prettyJsonBuilder = XContentFactory.jsonBuilder().prettyPrint();
prettyJsonBuilder.copyCurrentStructure(createParser(JsonXContent.jsonXContent, responseStrings));
assertThat(responseStrings, equalTo(prettyJsonBuilder.string()));
params.put("pretty", "false");
response = client().admin().indices().prepareGetFieldMappings("index").setTypes("type").setFields("field1", "obj.subfield").get();
responseBuilder = XContentFactory.jsonBuilder().prettyPrint().lfAtEnd();
responseBuilder.startObject();
response.toXContent(responseBuilder, new ToXContent.MapParams(params));
responseBuilder.endObject();
responseStrings = responseBuilder.string();
prettyJsonBuilder = XContentFactory.jsonBuilder().prettyPrint();
prettyJsonBuilder.copyCurrentStructure(createParser(JsonXContent.jsonXContent, responseStrings));
assertThat(responseStrings, not(equalTo(prettyJsonBuilder.string())));
}
Aggregations