# How to search with only raw query JSON with Elastic Java API 6.5.1?

**URL:** <https://discuss.elastic.co/t/how-to-search-with-only-raw-query-json-with-elastic-java-api-6-5-1/174310>\
**Category:** Elasticsearch\
**Created:** [March 28, 2019, 10:53am UTC](https://discuss.elastic.co/t/how-to-search-with-only-raw-query-json-with-elastic-java-api-6-5-1/174310 "2019-03-28T10:53:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![neerajjain92](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neerajjain92/32/41502_2.png) [@neerajjain92](https://discuss.elastic.co/u/neerajjain92)\
**Post date:** [March 28, 2019, 10:53am UTC](https://discuss.elastic.co/t/how-to-search-with-only-raw-query-json-with-elastic-java-api-6-5-1/174310/1 "2019-03-28T10:53:14Z")

</div>

How can I take the raw JSON String and query via the Java API? It should  
work for any complex query that Curl accepts in Elastic.

For example:

```
{
  "query": {
    "bool": {
      "must": [
        {
          "match_phrase": {
            "name": "<name>"
          }
        },
        {
          "match": {
            "address": {
              "query": "<address>",
              "fuzziness": 1,
              "prefix_length": 1,
              "operator": "or",
              "minimum_should_match": "80%"
            }
          }
        },
        {
          "match_phrase": {
            "city_nm": "<city_nm>"
          }
        },
        {
          "term": {
            "state_province_cd": "<state_province_cd>"
          }
        }
      ]
    }
  }
}

```

I tried `Query Builders' simpleQueryStringQuery` method to achieve this but it creates the query which doesn't give a correct result.

For Example, to search a record using just name, this is the query which `simpleQueryStringQuery` is generating but instead of returning just one record it returns multiple records.

```
{
  "query": {
    "simple_query_string": {
      "query": """{"query":{"bool":{"must":[{"match_phrase":{"name":"Neeraj"}}]}}}"""
    }
  }
}

```

whereas if I run the same query like this in my Kibana console that returns the correct number of results.

```
{
  "query": {
    "bool": {
      "must": [
        {
          "match_phrase": {
            "name": "Jaas"
          }
        }
      ]
    }
  }
}
```

---

<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:** [March 28, 2019, 12:04pm UTC](https://discuss.elastic.co/t/how-to-search-with-only-raw-query-json-with-elastic-java-api-6-5-1/174310/2 "2019-03-28T12:04:33Z")

</div>

If you want to just pass a JSON to any endpoint, you can use the Low Level client...

But if you want to mimic your QueryDSL with Java, you can use a boolQuery builder: [https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/6.7.0/org/elasticsearch/index/query/QueryBuilders.html#boolQuery--](https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/6.7.0/org/elasticsearch/index/query/QueryBuilders.html#boolQuery--)

And add all the must clauses you need with [https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/6.7.0/org/elasticsearch/index/query/BoolQueryBuilder.html#must(org.elasticsearch.index.query.QueryBuilder)](https://artifacts.elastic.co/javadoc/org/elasticsearch/elasticsearch/6.7.0/org/elasticsearch/index/query/BoolQueryBuilder.html#must(org.elasticsearch.index.query.QueryBuilder))

---

<div class="post-metadata">

**Author:** ![neerajjain92](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/neerajjain92/32/41502_2.png) [@neerajjain92](https://discuss.elastic.co/u/neerajjain92)\
**Post date:** [March 29, 2019, 7:38am UTC](https://discuss.elastic.co/t/how-to-search-with-only-raw-query-json-with-elastic-java-api-6-5-1/174310/3 "2019-03-29T07:38:38Z")

</div>

Can you please help me with the method name in low level client to be used for my requirement.

---

<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:** [March 29, 2019, 9:36am UTC](https://discuss.elastic.co/t/how-to-search-with-only-raw-query-json-with-elastic-java-api-6-5-1/174310/4 "2019-03-29T09:36:18Z")

</div>

Read [https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low-usage-requests.html](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low-usage-requests.html)

---

<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:** [April 26, 2019, 9:36am UTC](https://discuss.elastic.co/t/how-to-search-with-only-raw-query-json-with-elastic-java-api-6-5-1/174310/5 "2019-04-26T09:36:19Z")

</div>

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