Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get type names of elastic search index in internal java api or jest api

I have a index with the name of demo and it contains different types. I'm using elastic search java internal api and rest api jest both of them in my app. Basicly I want to make this request

curl -XGET 'http:localhost:9200/demo/_mapping'

Is there any way to do that especially in jest api? There seems to be no documentation to get mapping for rest client api. What should I do?

like image 970
Haktan Aydın Avatar asked Oct 24 '14 07:10

Haktan Aydın


People also ask

How do I find Elasticsearch index name?

There are multiple ways to list all of the indexes contained in an Elasticsearch cluster. One common way of doing this is to use cURL and Kibana to issue HTTP requests to communicate with the Elasticsearch cluster to have it return all of the index names and their respective UUIDs.

How do I get Elasticsearch index data?

You can use the search API to search and aggregate data stored in Elasticsearch data streams or indices. The API's query request body parameter accepts queries written in Query DSL. The following request searches my-index-000001 using a match query. This query matches documents with a user.id value of kimchy .

How do I list all indices in Elasticsearch?

You can query localhost:9200/_status and that will give you a list of indices and information about each. The response will look something like this: { "ok" : true, "_shards" : { ... }, "indices" : { "my_index" : { ... }, "another_index" : { ... } } }

Does Elasticsearch have an API?

One of the great things about Elasticsearch is its extensive REST API which allows you to integrate, manage and query the indexed data in countless different ways. Examples of using this API to integrate with Elasticsearch are abundant, spanning different companies and use cases.


1 Answers

This should work, but it's really ugly:

GetMappingsResponse res = client.admin().indices().getMappings(new GetMappingsRequest().indices("demo")).get();
ImmutableOpenMap<String, MappingMetaData> mapping  = res.mappings().get("demo");
for (ObjectObjectCursor<String, MappingMetaData> c : mapping) {
    System.out.println(c.key+" = "+c.value.source());
}

I don't know if this is officially supported or not -- I just found this by playing around.

like image 131
Alcanzar Avatar answered Dec 07 '22 23:12

Alcanzar