Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch: send JSON query string via Java client?

I am new to Elasticsearch. I read Elasticsearch's Java client APIs and am able to build query and send it to the Elasticsearch server via the transport client.

Because my query is quite complex with multi-level filters and I notice that it is cumbersome to build a query via the Java client. I feel that it is much simpler to build a JSON query string and then send it over to the Elasticsearch server via a Java client.

Is this something Elasticsearch offers?

I do like what Elasticsearch Java API can do after receiving results such as scrolling over the results. I want to keep these features.

Thanks for any input and links!

Regards.

like image 573
curious1 Avatar asked Dec 12 '22 04:12

curious1


1 Answers

Did further research on Elasticsearch API and found out that Elasticsearch does offer this capability. Here is how:

SearchResponse scrollResp = client.prepareSearch("my-index")
        .setTypes("my-type")
        .setSearchType(SearchType.SCAN)
        .setQuery(query) // **<-- Query string in JSON format**
        .execute().actionGet();
like image 196
curious1 Avatar answered Dec 13 '22 17:12

curious1