Created
February 11, 2019 09:26
-
-
Save ledangtuanbk/8076ad2ba6980292ca2b745e947dd63f to your computer and use it in GitHub Desktop.
This file contains 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) { | |
try { | |
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY) | |
.addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300)); | |
String jsonObject = "{\"age\":14,\"dateOfBirth\":1471466076564," | |
+"\"fullName\":\"John Doe\"}"; | |
IndexResponse response = client.prepareIndex("people", "Doe") | |
.setSource(jsonObject, XContentType.JSON).get(); | |
String id = response.getId(); | |
String index = response.getIndex(); | |
String type = response.getType(); | |
long version = response.getVersion(); | |
System.out.println(id); | |
System.out.println(index); | |
System.out.println(type); | |
System.out.println(version); | |
System.out.println(response.getResult()); | |
SearchResponse searchResponse = client.prepareSearch() | |
.setTypes() | |
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH) | |
.setPostFilter(QueryBuilders.rangeQuery("age").from(10).to(15)) | |
.execute() | |
.actionGet(); | |
List<SearchHit> searchHits = Arrays.asList(searchResponse.getHits().getHits()); | |
searchHits.forEach( | |
hit -> System.out.println(hit.getSourceAsString())); | |
}catch (Exception ex){ | |
ex.printStackTrace(); | |
} | |
} | |
Author
ledangtuanbk
commented
Feb 11, 2019
org.elasticsearch.client
transport
6.6.0
org.elasticsearch
elasticsearch
6.6.0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment