2

In Elastic search for retrieving data i tried to pass a json query through apache http client and elastic search rest high level client, Is there any other flexible way to pass the json query using java API ???Any help will be appreciate Thanks in advance


String query="";
SearchModule searchModule..
XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(new NamedXContentRegistry(searchModule
            .getNamedXContents()), query)
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
tisispa1
  • 203
  • 2
  • 3
  • 16
  • If you want to pass a JSON DSL query, you're better off using the [low-level REST client](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low-usage-requests.html). Using the high-level REST client requires you to build the query using [the Java DSL](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-search.html). – Val Sep 25 '19 at 11:22
  • is this okay to use low-level Rest client?? – tisispa1 Sep 25 '19 at 11:56
  • Of course it is. Even the Apache HTTP client is OK. It only depends on your use case and how you want to interact with ES. – Val Sep 25 '19 at 11:57
  • @Val okay!! I have another qus if suppose am using Apache ES protected with credentials how come I will pass the username , pwd through Apache?? – tisispa1 Sep 25 '19 at 12:01
  • 1
    As described in the [Apache client official documentation](https://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html) :-) – Val Sep 25 '19 at 12:06
  • yeah got it..!! And in `rest high level client` we can construct the search request and pass the JSON DSL Query right?? – tisispa1 Sep 25 '19 at 12:11
  • In the high level REST client, you can b64 encode your raw JSON query and pass it in a [wrapper query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-wrapper-query.html) – Val Sep 25 '19 at 12:13
  • @Val ```NamedXContentRegistry``` we can pass a json raw query AND ```XContentParser``` it will parse the raw query correct me if am wrong...? – tisispa1 Sep 25 '19 at 12:21
  • Can you show your query? – Val Sep 25 '19 at 12:24
  • @Val check this – tisispa1 Sep 25 '19 at 12:33

0 Answers0