# Elasticsearch fetching only schema using Java REST API

**URL:** <https://discuss.elastic.co/t/elasticsearch-fetching-only-schema-using-java-rest-api/70117>\
**Category:** Elasticsearch\
**Created:** [December 28, 2016, 8:23am UTC](https://discuss.elastic.co/t/elasticsearch-fetching-only-schema-using-java-rest-api/70117 "2016-12-28T08:23:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kumarroopesh](https://avatars.discourse-cdn.com/v4/letter/k/85f322/32.png) [@kumarroopesh](https://discuss.elastic.co/u/kumarroopesh)\
**Post date:** [December 28, 2016, 8:23am UTC](https://discuss.elastic.co/t/elasticsearch-fetching-only-schema-using-java-rest-api/70117/1 "2016-12-28T08:23:36Z")

</div>

Hi,  
When trying to fetch data from elasticsearch using Java rest API, I am getting only the schema as JSON, and not the data.  
Can you please help me.  
Here is what I am doing:

```
    RestClient restClient =
              RestClient.builder(new HttpHost("localhost", 9200, "http")).build();

    String query = "{\n" +
            "\"query\": {\n" +
            "\"bool\": {\n" +
            "\"must\": [\n" +
            " {\n" +
            " \"match_all\": {}\n" +
            " }\n" +
            "]\n" +
            "}\n" +
            "}\n" +
            "\"from\": 0,\n" +
            "\"size\": 10" +
            "}";

    HttpEntity entity = new NStringEntity(
            query, ContentType.APPLICATION_JSON);

    Response contentResponse =
            restClient.performRequest("GET", "/customers",
                    Collections.singletonMap("pretty", "true"), entity);
    String contentResult = EntityUtils.toString(contentResponse.getEntity()); 
    System.out.println("Content JSON : " + contentResult);

```

Please suggest.

---

<div class="post-metadata">

**Author:** ![ywelsch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ywelsch/32/7751_2.png) [@ywelsch](https://discuss.elastic.co/u/ywelsch)\
**Post date:** [December 28, 2016, 9:12am UTC](https://discuss.elastic.co/t/elasticsearch-fetching-only-schema-using-java-rest-api/70117/2 "2016-12-28T09:12:40Z")

</div>

> restClient.performRequest("GET", "/customers", ...

you have to use the correct endpoint, "/customers/\_search", see

> **[Search API | Elasticsearch Guide \[8.11\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html)**

---

<div class="post-metadata">

**Author:** ![kumarroopesh](https://avatars.discourse-cdn.com/v4/letter/k/85f322/32.png) [@kumarroopesh](https://discuss.elastic.co/u/kumarroopesh)\
**Post date:** [December 28, 2016, 12:10pm UTC](https://discuss.elastic.co/t/elasticsearch-fetching-only-schema-using-java-rest-api/70117/3 "2016-12-28T12:10:58Z")

</div>

Thanks @ywelsch,  
You are right. I tried with that also and that didn't work so I raised this question.  
Actually the query, I am sending was incorrect. I missed a comma ( , ).

The query should be :

```
String query = "{\n" +
        "\"query\": {\n" +
        "\"bool\": {\n" +
        "\"must\": [\n" +
        " {\n" +
        " \"match_all\": {}\n" +
        " }\n" +
        "]\n" +
        "}\n" +
        "},\n" +
        "\"from\": 0,\n" +
        "\"size\": 10" +
        "}"; 

```

Thanks again

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 25, 2017, 12:11pm UTC](https://discuss.elastic.co/t/elasticsearch-fetching-only-schema-using-java-rest-api/70117/4 "2017-01-25T12:11:31Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
