Search in sources :

Example 6 with GetFieldMappingsResponse

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();
}
Also used : GetFieldMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with GetFieldMappingsResponse

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());
}
Also used : GetFieldMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse)

Example 8 with GetFieldMappingsResponse

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())));
}
Also used : ToXContent(org.elasticsearch.common.xcontent.ToXContent) HashMap(java.util.HashMap) GetFieldMappingsResponse(org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Aggregations

GetFieldMappingsResponse (org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse)8 HashMap (java.util.HashMap)2 Map (java.util.Map)2 FieldMappingMetaData (org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.FieldMappingMetaData)2 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)2 IOException (java.io.IOException)1 GetFieldMappingsRequest (org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest)1 PutMappingResponse (org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse)1 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Strings (org.elasticsearch.common.Strings)1 Settings (org.elasticsearch.common.settings.Settings)1 ToXContent (org.elasticsearch.common.xcontent.ToXContent)1 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)1 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)1 RestController (org.elasticsearch.rest.RestController)1 RestRequest (org.elasticsearch.rest.RestRequest)1 GET (org.elasticsearch.rest.RestRequest.Method.GET)1 RestResponse (org.elasticsearch.rest.RestResponse)1 RestStatus (org.elasticsearch.rest.RestStatus)1