How to post data to elasticsearch from java application? What are the necessary Maven dependencies to make queries to elastic search engine?
I have done a lot of research but got confused.
Thanks in Advance !!!!!
You need to do the following:
Use IndexRequest
to index the document, eg:
IndexRequest request = new IndexRequest("<index_name>","<document_type>", "<document_id>"); request.source("<document_json>"); IndexResponse response = client.index(indexRequest).actionGet();
The latest version of Elasticsearch will be enough (look for the latest version in maven repository https://mvnrepository.com/artifact/org.elasticsearch ) :
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.4.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>rest</artifactId>
<version>5.4.0</version>
</dependency>
In addition, if you are familiar with scala (in java these operations are pretty much the same), you can use this XContentBuilder example to create json objects: https://github.com/sslavian812/needls2/blob/master/src/main/scala/ru/yandex/spark/ElasticSearchHelper.scala#L42
and this elasticsearch client request example: https://github.com/sslavian812/needls2/blob/master/src/main/scala/ru/yandex/spark/ElasticSearchHelper.scala#L125
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.