ElasticSearchv1.7.5 - How to pass ES boolQuery (in json string format) using highlevel rest client


#1

Hi,
I'm using ElasticSearch v1.7.5 (we cant upgrade to latest version due to other restrictions).

To call ES Search APIs I'm using highLevel Rest client (elasticsearch-rest-high-level-clientv5.6.0).

I need to pass the below request query to client.search() method.
Can you let us know how to pass a query (in string format) in SearchSourceBuilder.query() method?

Request payload:

{"query":{"filtered":{"filter":{"bool":{"must":[{"term":{"siteId":"1234"}},{"terms":{"studentId":["ram"]}},{"range":{"timestamp":{"from":"1501128000000","to":"1523469369861"}}}]}}}},"size":10000,"from":0,"sort":[{"timestamp":{"order":"asc"}}]}

Client Code:

RestClient restClient = RestClient.builder(new HttpHost(esHost, Integer.valueOf(esPort)))
.setDefaultHeaders(headers).build();
RestHighLevelClient client = new RestHighLevelClient(restClient);
SearchRequest searchRequest = new SearchRequest("INDEX-NAME");
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();

searchSourceBuilder.query( ??? );
searchSourceBuilder.fetchSource(true);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = client.search(searchRequest);

Thanks in advance for your help.

Regards
Suri


(Christian Dahlqvist) #2

This is as far as I know not compatible with Elasticsearch 1.7, so is unlikely to work. If you want to use the REST protocol from Java you may need to find an older client library that has support for version 1.7.

JEST might be an option, although I have never used it myself.


(system) #3

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