Skip to content

Instantly share code, notes, and snippets.

@visenger
Last active December 16, 2015 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save visenger/5498861 to your computer and use it in GitHub Desktop.
Save visenger/5498861 to your computer and use it in GitHub Desktop.
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.node.Node;
import java.io.IOException;
import java.util.Date;
import static org.elasticsearch.node.NodeBuilder.*;
import static org.elasticsearch.common.xcontent.XContentFactory.*;
public class EsTest {
public static void main(String[] args) {
try {
System.out.println("client starting....");
Node node = nodeBuilder().node();
Client client = node.client();
XContentBuilder builder = jsonBuilder().startObject()
.field("user", "chick")
.field("postDate", new Date())
.field("message", "trying out Elastic Search")
.endObject();
IndexResponse response = client
.prepareIndex("our_index", "idx_text", "1")
.setSource(builder)
.execute()
.actionGet();
String index = response.index();
String type = response.type();
System.out.println("index" + index + "type " + type);
node.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment