當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。