Search code examples
elasticsearchtypesaliasnest

How to fetch type of index from Alias or Index name?


I was wondering if there is any way to fetch type using Alias name or Index Name.


Solution

  • The type of index are related to document not Index itself, you can get a document and check the type of mapping. For more information check here: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-fields.html

    For Index you can get the mapping of Index then you can check how many Types do the index have to get Type of index you can use Get Mapping API:

    GET /my-index-000001/_mapping
    

    and if you want to use nest you can get info like this:

    client.Indices.GetMappingAsync<GetMappingResponse>();
    

    Remark: Mapping Types are deprecated in ES 6.x and above and will be removed in version 8 for more information check ES offical documentition here: https://www.elastic.co/guide/en/elasticsearch/reference/6.0/removal-of-types.html