samyo
(samyo)
June 7, 2019, 9:34am
1
hello Folks,
i am new on REST API in Java in order to send a simple String "Hello World" from Java Netbeans to Elasticsearch Index.
Can anybody please tell me how to write the Connection String in Netbeans to Put(send) the String "Hello World" in Elasticsearch Index?
I will be thankfull for any Answer.
dadoonet
(David Pilato)
June 7, 2019, 9:48am
2
What did you try so far from the documentation ?
Anyway here is an example:
Specifically this line of code:
}
}
private static void createData() {
try (RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(HttpHost.create("http://localhost:9200")))) {
try {
client.indices().delete(new DeleteIndexRequest("test"), RequestOptions.DEFAULT);
} catch (ElasticsearchStatusException ignored) { }
client.index(new IndexRequest("test").id("1").source("{\"foo\":\"bar\"}", XContentType.JSON), RequestOptions.DEFAULT);
client.indices().refresh(new RefreshRequest("test"), RequestOptions.DEFAULT);
SearchResponse response = client.search(new SearchRequest("test"), RequestOptions.DEFAULT);
System.out.println("response.getHits().totalHits = " + response.getHits().getTotalHits().value);
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}
samyo
(samyo)
June 7, 2019, 10:17am
3
thx for Response, i did not try anything yet from the documentation ?
it looks complicated for me, i though with just one Connection line in Netbeans , so that java will send the String "Hello World" automaticly to Elasticsearch, but it seems i have to download the jar_files for the Elasticsearch librarys https://jar-download.com/artifacts/org.elasticsearch.client/elasticsearch-rest-high-level-client/6.2.4/source-code , and what should i exactly import in Netbeans?
dadoonet
(David Pilato)
June 7, 2019, 12:11pm
4
You're new to Java/Maven/Gradle, right?
Anyway that's more a netbean question than an elasticsearch question. I don't know netbean so I guess you'd better ask on their forum.
If you have any question regarding to elasticsearch client feel free to ask here.
system
(system)
Closed
July 5, 2019, 12:11pm
5
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.