当前位置: 首页>>代码示例>>Java>>正文


Java TransportClient.close方法代码示例

本文整理汇总了Java中org.elasticsearch.client.transport.TransportClient.close方法的典型用法代码示例。如果您正苦于以下问题:Java TransportClient.close方法的具体用法?Java TransportClient.close怎么用?Java TransportClient.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.client.transport.TransportClient的用法示例。


在下文中一共展示了TransportClient.close方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked", "resource"})
public static void main(String[] args) throws Exception {
	// 先构建client,两个参数分别是:cluster.name 固定参数代表后面参数的含义,集群名称
	// client.transport.sniff 表示设置自动探查集群的集群节点
	Settings settings = Settings.builder()
			.put("cluster.name", "youmeek-cluster")
			.put("client.transport.sniff", true)
			.build();

	//单个节点的写法
	TransportClient transportClient = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.1.127"), 9300));

	//batchCreate(transportClient);
	query(transportClient);

	transportClient.close();
}
 
开发者ID:judasn,项目名称:Elasticsearch-Tutorial-zh-CN,代码行数:18,代码来源:ElasticsearchGis.java

示例2: main

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked", "resource"})
public static void main(String[] args) throws IOException {
	// 先构建client,两个参数分别是:cluster.name 固定参数代表后面参数的含义,集群名称
	// client.transport.sniff 表示设置自动探查集群的集群节点
	Settings settings = Settings.builder()
			.put("cluster.name", "youmeek-cluster")
			.put("client.transport.sniff", true)
			.build();

	//单个节点的写法
	TransportClient transportClient = new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.1.127"), 9300));

	//======================================================

	create(transportClient);
	batchCreate(transportClient);
	batchUpdate(transportClient);
	batchDelete(transportClient);
	update(transportClient);
	query(transportClient);
	queryByMatchOneParam(transportClient);
	queryByMatchMoreParam(transportClient);
	queryByTerm(transportClient);
	queryByPrefix(transportClient);
	queryByBool(transportClient);
	queryMore(transportClient);
	queryByMultiGet(transportClient);
	queryByScroll(transportClient);
	queryByTemplate(transportClient);
	delete(transportClient);
	aggregate(transportClient);

	//======================================================

	transportClient.close();
}
 
开发者ID:judasn,项目名称:Elasticsearch-Tutorial-zh-CN,代码行数:37,代码来源:BaseDemo.java

示例3: test1

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
@Test
public void test1(){
    try{
        Settings settings = Settings.builder()
                .put("cluster.name", "xmall").build();
        TransportClient client = new PreBuiltTransportClient(settings)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("123.207.121.135"), 9300));

        IndexResponse response = client.prepareIndex("item", "itemList", "830972")
                .setSource(jsonBuilder()
                        .startObject()
                        .field("productId", "830972")
                        .field("salePrice", "254")
                        .field("productName", "254")
                        .field("sub_title", "524")
                        .field("productImageBig", "252")
                        .field("category_name", "2542")
                        .endObject()
                ).get();

        GetResponse getResponse = client.prepareGet("item", "itemList", "830972").get();

        String json = getResponse.getSourceAsString();

        System.out.println(json);

        client.close();
    }catch (Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:Exrick,项目名称:xmall,代码行数:32,代码来源:ElasticsearchTest.java

示例4: test

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
@Test
    public void test() {

        try {
            Settings settings = Settings.builder().put("cluster.name", "elasticsearch")
                    .build();

            TransportClient client = new PreBuiltTransportClient(settings)
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
//            IndexResponse response = client.prepareIndex("twitter", "tweet", "1")
//                    .setSource(jsonBuilder()
//                            .startObject()
//                            .field("user", "kimchy")
//                            .field("postDate", new Date())
//                            .field("message", "trying out Elasticsearch")
//                            .endObject()
//                    )
//                    .get();
//            System.out.println(response);

            Map<String,Object> result = new HashMap<>();
            result.put("user","Mary6");
            result.put("postDate",new Date());
            result.put("massage","this is Mary6");

            IndexResponse response2 = client.prepareIndex("twitter","tweet")
                    .setSource(result).get();
            System.out.println(response2.status().name().equals("CREATED"));



            client.close();

        } catch (Exception e) {
            e.printStackTrace();
        }


    }
 
开发者ID:java-webbee,项目名称:webBee,代码行数:40,代码来源:TestElasticsearch.java

示例5: closeClient

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
public void closeClient(TransportClient client) {
    if (client != null) {
        client.close();
    }
}
 
开发者ID:sundarcse1216,项目名称:es-crud,代码行数:6,代码来源:ElasticSearchClient.java

示例6: ExternalTestCluster

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
public ExternalTestCluster(Path tempDir, Settings additionalSettings, Collection<Class<? extends Plugin>> pluginClasses,
                           TransportAddress... transportAddresses) {
    super(0);
    Settings.Builder clientSettingsBuilder = Settings.builder()
        .put(additionalSettings)
        .put("node.name", InternalTestCluster.TRANSPORT_CLIENT_PREFIX + EXTERNAL_CLUSTER_PREFIX + counter.getAndIncrement())
        .put("client.transport.ignore_cluster_name", true)
        .put(Environment.PATH_HOME_SETTING.getKey(), tempDir);
    boolean addMockTcpTransport = additionalSettings.get(NetworkModule.TRANSPORT_TYPE_KEY) == null;

    if (addMockTcpTransport) {
        clientSettingsBuilder.put(NetworkModule.TRANSPORT_TYPE_KEY, MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME);
        if (pluginClasses.contains(MockTcpTransportPlugin.class) == false) {
            pluginClasses = new ArrayList<>(pluginClasses);
            pluginClasses.add(MockTcpTransportPlugin.class);
        }
    }
    Settings clientSettings = clientSettingsBuilder.build();
    TransportClient client = new MockTransportClient(clientSettings, pluginClasses);

    try {
        client.addTransportAddresses(transportAddresses);
        NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().clear().setSettings(true).setHttp(true).get();
        httpAddresses = new InetSocketAddress[nodeInfos.getNodes().size()];
        this.clusterName = nodeInfos.getClusterName().value();
        int dataNodes = 0;
        int masterAndDataNodes = 0;
        for (int i = 0; i < nodeInfos.getNodes().size(); i++) {
            NodeInfo nodeInfo = nodeInfos.getNodes().get(i);
            httpAddresses[i] = nodeInfo.getHttp().address().publishAddress().address();
            if (DiscoveryNode.isDataNode(nodeInfo.getSettings())) {
                dataNodes++;
                masterAndDataNodes++;
            } else if (DiscoveryNode.isMasterNode(nodeInfo.getSettings())) {
                masterAndDataNodes++;
            }
        }
        this.numDataNodes = dataNodes;
        this.numMasterAndDataNodes = masterAndDataNodes;
        this.client = client;
        logger.info("Setup ExternalTestCluster [{}] made of [{}] nodes", nodeInfos.getClusterName().value(), size());
    } catch (Exception e) {
        client.close();
        throw e;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:47,代码来源:ExternalTestCluster.java

示例7: onMessage

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
@Override
public void onMessage(Message message) {
	try {
		//从消息中取商品id
		TextMessage textMessage = (TextMessage) message;

		log.info("得到消息:"+textMessage.getText());

		String[] text = textMessage.getText().split(",");
		Long itemId = new Long(text[1]);
		//等待事务提交
		Thread.sleep(1000);

		//更新索引
		Settings settings = Settings.builder()
				.put("cluster.name", "xmall").build();
		TransportClient client = new PreBuiltTransportClient(settings)
				.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ES_CONNECT_IP), 9300));

		if(text[0].equals("add")){
			//根据商品id查询商品信息
			SearchItem searchItem = itemMapper.getItemById(itemId);
			String image=searchItem.getProductImageBig();
			if (image != null && !"".equals(image)) {
				String[] strings = image.split(",");
				image=strings[0];
			}else{
				image="";
			}
			searchItem.setProductImageBig(image);
			IndexResponse indexResponse = client.prepareIndex(ITEM_INDEX, ITEM_TYPE, String.valueOf(searchItem.getProductId()))
					.setSource(jsonBuilder()
							.startObject()
							.field("productId", searchItem.getProductId())
							.field("salePrice", searchItem.getSalePrice())
							.field("productName", searchItem.getProductName())
							.field("sub_title", searchItem.getSub_title())
							.field("productImageBig", searchItem.getProductImageBig())
							.field("category_name", searchItem.getCategory_name())
							.endObject()
					).get();
		}else if(text[0].equals("delete")){
			DeleteResponse deleteResponse = client.prepareDelete(ITEM_INDEX, ITEM_TYPE, String.valueOf(itemId)).get();
		}

		log.info("处理消息成功");

		client.close();

	} catch (Exception e) {
		e.printStackTrace();
	}

}
 
开发者ID:Exrick,项目名称:xmall,代码行数:55,代码来源:ItemESMessageListener.java

示例8: importAllItems

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
@Override
public int importAllItems() {

	try{
		Settings settings = Settings.builder()
				.put("cluster.name", "xmall").build();
		TransportClient client = new PreBuiltTransportClient(settings)
				.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(ES_CONNECT_IP), 9300));

		//批量添加
		BulkRequestBuilder bulkRequest = client.prepareBulk();

		//查询商品列表
		List<SearchItem> itemList = itemMapper.getItemList();

		//遍历商品列表
		for (SearchItem searchItem : itemList) {
			String image=searchItem.getProductImageBig();
			if (image != null && !"".equals(image)) {
				String[] strings = image.split(",");
				image=strings[0];
			}else{
				image="";
			}
			searchItem.setProductImageBig(image);
			bulkRequest.add(client.prepareIndex("item", "itemList", String.valueOf(searchItem.getProductId()))
					.setSource(jsonBuilder()
							.startObject()
							.field("productId", searchItem.getProductId())
							.field("salePrice", searchItem.getSalePrice())
							.field("productName", searchItem.getProductName())
							.field("sub_title", searchItem.getSub_title())
							.field("productImageBig", searchItem.getProductImageBig())
							.field("category_name", searchItem.getCategory_name())
							.endObject()
					)
			);
		}

		BulkResponse bulkResponse = bulkRequest.get();

		log.info("更新索引成功");

		client.close();
	}catch (Exception e){
		e.printStackTrace();
		throw new XmallException("导入ES索引库出错");
	}

	return 1;
}
 
开发者ID:Exrick,项目名称:xmall,代码行数:52,代码来源:SearchItemServiceImpl.java

示例9: main

import org.elasticsearch.client.transport.TransportClient; //导入方法依赖的package包/类
public static void main(String[] args) {

        TransportClient client = new PreBuiltTransportClient(Settings.EMPTY);

        client.addTransportAddress(new InetSocketTransportAddress(new InetSocketAddress("127.0.0.1", 9300)));

        IndexRequestBuilder irb = client.prepareIndex("uav_test_db", "uav_test_table");

        Map<String, Object> item = new HashMap<String, Object>();

        item.put("name", "zz");
        item.put("age", 1);

        irb.setSource(item);

        IndexResponse ir = irb.get();

        System.out.println(ir.status());

        client.close();
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:22,代码来源:DoTestESClient.java


注:本文中的org.elasticsearch.client.transport.TransportClient.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。