# Executing JSON query directly using Java API ignore the query algother

**URL:** <https://discuss.elastic.co/t/executing-json-query-directly-using-java-api-ignore-the-query-algother/351897>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [January 26, 2024, 6:25pm UTC](https://discuss.elastic.co/t/executing-json-query-directly-using-java-api-ignore-the-query-algother/351897 "2024-01-26T18:25:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinitp](https://avatars.discourse-cdn.com/v4/letter/v/46a35a/32.png) [@vinitp](https://discuss.elastic.co/u/vinitp)\
**Post date:** [January 26, 2024, 6:25pm UTC](https://discuss.elastic.co/t/executing-json-query-directly-using-java-api-ignore-the-query-algother/351897/1 "2024-01-26T18:25:23Z")

</div>

In my application, we build the search query in JSON format.e.g

```auto
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "officeCode.keyword": {
              "value": "410"
            }
          }
        },
        {
          "terms": {
            "status.keyword": [
              "CLOSED",
              "CREDIT"
            ]
          }
        }
        ]
    }
  }
}

```

We use Elasticsearch Java 8.X API to execute the query using "co.elastic.clients.elasticsearch.ElasticsearchClient;"

```auto
String encodedJson = Base64.getEncoder().encodeToString(jsonQuery.getBytes());
     SearchResponse<Map> searchResponse = elasticsearchClient.search(s -> s
                    .index(indexName)
                    .query(b -> b.queryString(b1 -> b1.query(encodedJson ))), Map.class);

```

I noticed that it completely ignores the query and returns the default max size. It does not throw an error, either. I also try to use the native JSON without encoding, but then it throws a "sharding error".

---

<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:** [February 23, 2024, 6:25pm UTC](https://discuss.elastic.co/t/executing-json-query-directly-using-java-api-ignore-the-query-algother/351897/2 "2024-02-23T18:25:34Z")

</div>

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