Hi ganesh
First create a ES client in your java application.
private org.elasticsearch.client.Client client;
Initialize it, (google Elasticsearch Node client, and Transport Client)
Settings settings = ImmutableSettings
.settingsBuilder()
.put("cluster.name","elasticsearchcluster")
.build();
try{
client=
new TransportClient(settings)
.addTransportAddress(new
InetSocketTransportAddress("192.168.145.144",9300));
}catch(Exception e)
{
e.printStackTrace();
}
Create a indexRequest, with IndexName , Document Type ( + ID-optional ) ,
set it's source as the data that you want to index. Source can be either a
map , or a string etc.
IndexRequest indexRequest=new
IndexRequest("indexName","documentType");
then execute the request by
client.index(INDEXREQUEST).actionGet();
By exxecuting this request , if your index , "indexName" is not present ,
elasticsearch will create it automatically , with some default mapping for
the document "documentType" you have sent to it to be indexed.
You can batch multiple Reuests, using the Bulk Api , you can create/specify
custom mappings for your document and control how individual fields are to
be indexed , are they going to be stored or not etc, but the above part is
just the basic level gist of getting you started.
Hoping that this helps.
Thanks
Tarang Dawer
On Wed, Jun 5, 2013 at 4:19 AM, ganesh sainath ganesh10888@gmail.comwrote:
Hi All,
I am new to Elastic Search.
What I need is to insert data in to Elastic search using Java. I am not
able to find any sample program to have as base that would help me connect
to Elastic search. It would be great if any of you can guide me to
appropriate links or post some sample code for the same.
Thanks,
Ganesh Sainath
--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.