Created
October 25, 2021 07:03
-
-
Save silicontrip/fe0373a60cec74a7707bf05ec1620215 to your computer and use it in GitHub Desktop.
example static method to make an elasticsearch query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) | |
{ | |
RestClientBuilder cb = RestClient.builder(new HttpHost("10.35.38.214", 9200)); // configure | |
RestHighLevelClient client = new RestHighLevelClient(cb); | |
// Transport transport = new RestClientTransport(restClient, new JacksonJsonpMapper()); | |
// ElasticsearchClient client = new ElasticsearchClient(transport); | |
// MultiGetRequest mgRequest = new MultiGetRequest(); | |
// GetRequest getRequest = new GetRequest("quick_look"); | |
SearchRequest searchRequest = new SearchRequest("quick_look"); | |
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder(); | |
sourceBuilder.query(QueryBuilders.matchAllQuery()); | |
searchRequest.source(sourceBuilder); | |
try { | |
SearchResponse search = client.search(searchRequest, RequestOptions.DEFAULT); | |
// GetResponse gr = client.get(getRequest, RequestOptions.DEFAULT); | |
System.out.println("res: " + search); | |
} catch (IOException ioe) { | |
System.out.println("something has gone wrong: " + ioe.getMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment