java elasticsearch index
2021-06-03 21:03
标签:通过 carp date() text ack write execution row turn es版本6.8.*及以下,7.9.*不适用。 直接贴代码 java elasticsearch index 标签:通过 carp date() text ack write execution row turn 原文地址:https://www.cnblogs.com/zhanchaohan/p/14668868.htmlimport java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
import org.elasticsearch.action.admin.indices.stats.IndexStats;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* 定义es index格式
*
* @author zhanchaohan
* @see https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-docs-index.html
*/
public class index {
private TransportClient client;
@Before
public void init() throws FileNotFoundException, IOException {
ElasticConfig ec = new ElasticConfig();
client = ec.init();
}
@After
public void destroy() {
if (client != null) {
client.close();
}
}
@Test
public void testIndex() throws IOException {
// json
String json = "{" + "\"user\":\"kimchy\"," + "\"postDate\":\"2013-01-30\","
+ "\"message\":\"trying out Elasticsearch\"" + "}";
// 通过Map
Map
文章标题:java elasticsearch index
文章链接:http://soscw.com/index.php/essay/90132.html