Using Java API, how do I find out whether a given type exists in the index?

I am using the following line to delete the mapping for a type.

client.admin().indices().prepareDeleteMapping().setType("SUPPLIER_CODE_1").execute().actionGet();

How do I check whether the "TYPE" "SUPPLIER_CODE_1" exists in the index
before I try to delete it? Right now, if the TYPE doesn't exists, ES throws
few exceptions, which is expected I guess. I just want things to be clean.

Also I wonder whether this is the correct method to clear the index for a
given TYPE.

Please help.

Thanks
Mxims

--

I think it looks something like this...

ClusterStateResponse resp =
client.admin().cluster().prepareState().execute().actionGet();
Map<String, MappingMetaData> mappings =
resp.state().metaData().index(index).mappings();
if (mappings.containsKey(type)) {/* type exists */}

Deleting the mapping...

client.admin().indices().deleteMapping(mapping_name).actionGet();

On Friday, January 18, 2013 6:31:12 PM UTC-5, Mxims wrote:

I am using the following line to delete the mapping for a type.

client.admin().indices().prepareDeleteMapping().setType("SUPPLIER_CODE_1").execute().actionGet();

How do I check whether the "TYPE" "SUPPLIER_CODE_1" exists in the index
before I try to delete it? Right now, if the TYPE doesn't exists, ES throws
few exceptions, which is expected I guess. I just want things to be clean.

Also I wonder whether this is the correct method to clear the index for a
given TYPE.

Please help.

Thanks
Mxims

--

Hi egaumer,

Thank you so much for your help!

Here is what I did.. it worked :slight_smile: Have a great weekend.

    ClusterStateResponse resp = 

client.admin().cluster().prepareState().execute().actionGet();
Map mappings = resp.state().metaData().index("supplier").mappings();
System.out.println("mappings " + mappings);

    //if (mappings.containsKey(type)) {/* type exists */}

    MappingMetaData data = (MappingMetaData) mappings.get("0000112275");

    System.out.println("data >>>>>>>> " + data.type());
    System.out.println("data >>>>>>>> " + data.getSourceAsMap());
    DeleteMappingRequest req = new DeleteMappingRequest("supplier");
    req.type(data.type());
    client.admin().indices().deleteMapping(req).actionGet();

Thanks

On Friday, January 18, 2013 4:11:22 PM UTC-8, egaumer wrote:

I think it looks something like this...

ClusterStateResponse resp =
client.admin().cluster().prepareState().execute().actionGet();
Map<String, MappingMetaData> mappings =
resp.state().metaData().index(index).mappings();
if (mappings.containsKey(type)) {/* type exists */}

Deleting the mapping...

client.admin().indices().deleteMapping(mapping_name).actionGet();

On Friday, January 18, 2013 6:31:12 PM UTC-5, Mxims wrote:

I am using the following line to delete the mapping for a type.

client.admin().indices().prepareDeleteMapping().setType("SUPPLIER_CODE_1").execute().actionGet();

How do I check whether the "TYPE" "SUPPLIER_CODE_1" exists in the index
before I try to delete it? Right now, if the TYPE doesn't exists, ES throws
few exceptions, which is expected I guess. I just want things to be clean.

Also I wonder whether this is the correct method to clear the index for a
given TYPE.

Please help.

Thanks
Mxims

--