This example i will show how to use java api for search from elastic search server that i config on this topic install elastic search on ubuntu 12.04. this example is simple search using java api if you need advance you can learn more at http://www.elasticsearch.org/guide/reference/java-api/search/
Create ElasticSearch.java and have the following code.
package com.blogspot.na5cent.elasticsearch;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.transport.TransportAddress;
/**
*
* @author redcrow
*/
public abstract class ElasticSearch {
//point to elastic search server
private TransportAddress transportAddress = new InetSocketTransportAddress("192.168.1.34", 9300);
//implements by another, return client to argument
public abstract void perform(Client client);
public void execute() {
Client client = null;
try {
client = new TransportClient().addTransportAddress(transportAddress);
perform(client);
} finally {
if (client != null) {
client.close();
}
}
}
}
Search.java