# How to write Match\_all Search Query in Low Level Rest Client API

**URL:** <https://discuss.elastic.co/t/how-to-write-match-all-search-query-in-low-level-rest-client-api/189513>\
**Category:** Elasticsearch\
**Created:** [July 9, 2019, 10:00am UTC](https://discuss.elastic.co/t/how-to-write-match-all-search-query-in-low-level-rest-client-api/189513 "2019-07-09T10:00:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![samyo](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@samyo](https://discuss.elastic.co/u/samyo)\
**Post date:** [July 9, 2019, 10:00am UTC](https://discuss.elastic.co/t/how-to-write-match-all-search-query-in-low-level-rest-client-api/189513/1 "2019-07-09T10:00:41Z")

</div>

Hello folks,  
i need some help please , to write a correct Search Query to match all things inside my Index in Elasticsearch .

I want also to translate this Query in Java Low Level Rest Client API.

```auto
GET try1/_search
{
  "query": {
    "match_all": {}
  }
}

```

I tried something like this bellow , and it gives me nothing from the Index.  
I do now know where to put my Index name to search bellow,

```auto
SearchRequestBuilder sr = new SearchRequestBuilder(client, SearchAction.INSTANCE)
                            .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
                            .setQuery(QueryBuilders.matchAllQuery());

```

the Code above returns me this ,

```auto
{"query":{"match_all":{"boost":1.0}}}

```

I tried this too , and did not work, bellow ,

```auto
SearchRequest searchRequest = new SearchRequest("try1");
                    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
                    searchSourceBuilder.query(QueryBuilders.matchAllQuery());
                    searchRequest.source(searchSourceBuilder);

```

the Result is ,

```auto
{searchType=QUERY_THEN_FETCH, indices=[try1], indicesOptions=IndicesOptions[id=38, ignore_unavailable=false, allow_no_indices=true, expand_wildcards_open=true, expand_wildcards_closed=false, allow_aliases_to_multiple_indices=true, forbid_closed_indices=true, ignore_aliases=false], types=[], routing='null', preference='null', requestCache=null, scroll=null, maxConcurrentShardRequests=0, batchedReduceSize=512, preFilterShardSize=128, allowPartialSearchResults=null, source={"query":{"match_all":{"boost":1.0}}}}

```

Can Anybody please help me to write the Search Query to match\_all in the right way using Low Level Client Rest API ???

thx.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 9, 2019, 9:06pm UTC](https://discuss.elastic.co/t/how-to-write-match-all-search-query-in-low-level-rest-client-api/189513/2 "2019-07-09T21:06:01Z")

</div>

Are you sure you want to use the low level client and not the high level one?

---

<div class="post-metadata">

**Author:** ![samyo](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@samyo](https://discuss.elastic.co/u/samyo)\
**Post date:** [July 10, 2019, 6:58am UTC](https://discuss.elastic.co/t/how-to-write-match-all-search-query-in-low-level-rest-client-api/189513/3 "2019-07-10T06:58:57Z")

</div>

yes i want to give the Low Level Client a try , i use actually the **TransportClient** , to Creat Index and send Data to Elasticsearch , is there any Option , to use my TransportClient in order to write the Match\_all Search Query in a right Way???  
**I am not using** the RestClient , is there any different between both????

I Used the High Level Client too like this bellow , and still even did not give me the Content of the Index ,

```auto
try (RestHighLevelClient client = new RestHighLevelClient(
                RestClient.builder(HttpHost.create("http://localhost:9200")))) {
            SearchRequest searchRequest = new SearchRequest("try1");
            SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.query(QueryBuilders.matchAllQuery());
            searchRequest.source(searchSourceBuilder);
            System.out.println("searchrequest is : " + searchRequest);
}

```

The Result of this High Level Client Query is ,

```auto
{searchType=QUERY_THEN_FETCH, indices=[try1], indicesOptions=IndicesOptions[id=38, ignore_unavailable=false, allow_no_indices=true, expand_wildcards_open=true, expand_wildcards_closed=false, allow_aliases_to_multiple_indices=true, forbid_closed_indices=true, ignore_aliases=false], types=[], routing='null', preference='null', requestCache=null, scroll=null, maxConcurrentShardRequests=0, batchedReduceSize=512, preFilterShardSize=128, allowPartialSearchResults=null, source={"query":{"match_all":{"boost":1.0}}}}

```

Nothing seems to work correctly . Cause i need the Content of the Index under "\_source".

Any Suggestion i will be thankfull.

---

<div class="post-metadata">

**Author:** ![samyo](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@samyo](https://discuss.elastic.co/u/samyo)\
**Post date:** [July 10, 2019, 9:06am UTC](https://discuss.elastic.co/t/how-to-write-match-all-search-query-in-low-level-rest-client-api/189513/4 "2019-07-10T09:06:14Z")

</div>

I tried again with the RestClient API insead of TransportClient like bellow,

```auto
     RestClient restClient = RestClient.builder(
                            new HttpHost("localhost", 9200, "http")).build();
                    RestClientBuilder builder = RestClient.builder(new HttpHost("localhost", 9200, "http"));
                    Response response1 = restClient.performRequest("GET","try1");//here the IndexName
                    RequestLine requestLine = response1.getRequestLine();
                    HttpHost host = response1.getHost();
                    int statusCode = response1.getStatusLine().getStatusCode();
                    //org.apache.http.Header[] headers = response1.getHeaders();
                    String responseBody = EntityUtils.toString( response1.getEntity());
                    System.out.println("result is : " + responseBody);

```

The Result seems to be better, cause it returns the Typs of all Fields of my Index , like bellow ,

```auto
{"try1":{"aliases":{},"mappings":{"_doc":{"properties":{"my_id":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"field":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}},"gender":{"type":"text","fields":{"keyword":{"type":"keyword","ignore_above":256}}}}}},"settings":{"index":{"creation_date":"1561710794108","number_of_shards":"5","number_of_replicas":"1","uuid":"IWI-z1wPRXiUt3N3RINEYw","version":{"created":"6030199"},"provided_name":"try1"}}}}

```

I just need the Values inseatd of the Typs of Fields . Is there any Option to do that ??

thx

---

<div class="post-metadata">

**Author:** ![samyo](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@samyo](https://discuss.elastic.co/u/samyo)\
**Post date:** [July 10, 2019, 9:41am UTC](https://discuss.elastic.co/t/how-to-write-match-all-search-query-in-low-level-rest-client-api/189513/5 "2019-07-10T09:41:03Z")

</div>

So i have resolved it like bellow , but still have a littel Question.

```auto
     RestClient restClient = RestClient.builder(
                            new HttpHost("localhost", 9200, "http")).build();
                    //RestClientBuilder builder = RestClient.builder(new HttpHost("localhost", 9200, "http"));
                   // Map<String, String> params = Collections.singletonMap("gender", "Ahoiii");

           Response response1 = restClient.performRequest("GET","/try1/_doc/1"); // here is the secret
                    RequestLine requestLine = response1.getRequestLine();
                    HttpHost host = response1.getHost();
                    int statusCode = response1.getStatusLine().getStatusCode();
                    //org.apache.http.Header[] headers = response1.getHeaders();
                    String responseBody = EntityUtils.toString( response1.getEntity());
                    System.out.println("result is : " + responseBody);

```

result is,

```auto
result is : {"_index":"try1","_type":"_doc","_id":"1","_version":4,"found":true,"_source":{"my_id":"6","gender":"Ahoiii"}}

```

I need to write this

```auto
Response response1 = restClient.performRequest("GET","/try1/_doc/1"); 

```

correctly to give me all Entity with their different "\_id's" , not just the "\_doc" with "\_id =1 ".  
Cause in my Index there are more than one \_id .  
Can you please help me do this??

thx.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 10, 2019, 10:33am UTC](https://discuss.elastic.co/t/how-to-write-match-all-search-query-in-low-level-rest-client-api/189513/6 "2019-07-10T10:33:07Z")

</div>

Could you express what you want to do with a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Then when we know exactly what you want to do, we can translate that to Java code.

---

<div class="post-metadata">

**Author:** ![samyo](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@samyo](https://discuss.elastic.co/u/samyo)\
**Post date:** [July 10, 2019, 11:11am UTC](https://discuss.elastic.co/t/how-to-write-match-all-search-query-in-low-level-rest-client-api/189513/7 "2019-07-10T11:11:09Z")

</div>

I just want to translet the Match\_all Search Query using either TransportClient in Low Level Rest Client, or RestClient in Low Level Rest Client.  
I want just the same Result wich this Query gives , but on my Programm Console using one of the above Low Level Clients.  
This Search query will give me all Content of my Index , that mean every Entity and every Field with its Value too .

```auto
GET try1/_search
{
  "query": {
    "match_all": {}
  }
}

```

That is all the Idea about.  
thx.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 10, 2019, 12:52pm UTC](https://discuss.elastic.co/t/how-to-write-match-all-search-query-in-low-level-rest-client-api/189513/8 "2019-07-10T12:52:07Z")

</div>

Easiest way:

```auto
try (RestHighLevelClient client = new RestHighLevelClient(
        RestClient.builder(HttpHost.create("http://localhost:9200")))) {
    SearchResponse response = client.search(new SearchRequest("test"), RequestOptions.DEFAULT);
} catch (Exception e) {
    e.printStackTrace(System.err);
}

```

Or:

```auto
try (RestHighLevelClient client = new RestHighLevelClient(
        RestClient.builder(HttpHost.create("http://localhost:9200")))) {
    SearchResponse response = client.search(new SearchRequest("test")
            .source(new SearchSourceBuilder().query(
                    QueryBuilders.matchAllQuery()
                    )
            ), RequestOptions.DEFAULT);
} catch (Exception e) {
    e.printStackTrace(System.err);
}

```

---

<div class="post-metadata">

**Author:** ![samyo](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@samyo](https://discuss.elastic.co/u/samyo)\
**Post date:** [July 10, 2019, 1:29pm UTC](https://discuss.elastic.co/t/how-to-write-match-all-search-query-in-low-level-rest-client-api/189513/9 "2019-07-10T13:29:22Z")

</div>

i tried both , they did not work , and throw me this Failure,

```auto
faild Elasticsearch exception [type=illegal_argument_exception, reason=request [/test/_search] contains unrecognized parameters: [ccs_minimize_roundtrips], [ignore_throttled]]

```

what is the Reason of that ?  
thx

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 10, 2019, 1:55pm UTC](https://discuss.elastic.co/t/how-to-write-match-all-search-query-in-low-level-rest-client-api/189513/10 "2019-07-10T13:55:00Z")

</div>

Because you are not using the same version for the client and the server most likely.

---

<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:** [August 7, 2019, 1:55pm UTC](https://discuss.elastic.co/t/how-to-write-match-all-search-query-in-low-level-rest-client-api/189513/11 "2019-08-07T13:55:12Z")

</div>

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