java连接elastic search 9300
java连接elastic search
导入jar包:https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/_maven_repository.html
注意,使用的jar包版本尽量与所连的els版本一致
创建连接:https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/transport-client.html
查询:https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/java-search.html

发现两个错误:
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
错误原因:java连接els用到了log4j2,所以需要log4j2-core的依赖
解决办法:添加log4j2-core依赖
https://www.elastic.co/guide/en/elasticsearch/client/java-api/5.5/_log4j_2_logger.html
NoNodeAvailableException[None of the configured nodes are available: [{#
错误原因:创建连接时需要配置cluster_name。
elasticsearch服务器的cluster_name可以在#els_home#/config/elasticsearch.yml文件中配置。

然后在java客户端程序中将
TransportClient client=new PreBuiltTransportClient(Settings.EMPTY).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("139.199.32.101"),9300));
改为
Settings settings=Settings.builder().put("cluster.name","production").build();
TransportClient client=new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("139.199.32.101"),9300));
JAVA客户端代码:
package com.tpot.DataDownload; import java.net.InetAddress;
import java.net.UnknownHostException; //import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
//import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient; /**
* Hello world!
*
*/
public class App
{
public static void main( String[] args ) throws UnknownHostException
{
System.out.println( "Hello World!" ); //连接+配置
Settings settings=Settings.builder().put("cluster.name","production").build();
TransportClient client=new PreBuiltTransportClient(settings).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("139.xxx.xxx.101"),9300)); //查询
SearchResponse response = client.prepareSearch().get();
System.out.println(response); //关闭连接
client.close();
}
}
pom.xml文件中添加的依赖:
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.5.3</version>
</dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.2</version>
</dependency>
java连接elastic search 9300的更多相关文章
- elastic search&logstash&kibana 学习历程(一)es基础环境的搭建
elastic search 6.1.x 常用框架: 1.Lucene Apache下面的一个开源项目,高性能的.可扩展的工具库,提供搜索的基本架构: 如果开发人员需用使用的话,需用自己进行开发,成本 ...
- elastic search book [ ElasticSearch book es book]
谁在使用ELK 维基百科, github都使用 ELK (ElasticSearch es book) ElasticSearch入门 Elasticsearch入门,这一篇就够了==>http ...
- elastic search远程测试
elastic search远程测试 推荐:elastic官方教程:https://www.elastic.co/guide/en/elasticsearch/reference/6.2/index. ...
- elastic search安装与本地测试
elastic search安装与本地测试 elastic search是一个全文搜索引擎 教程: 综合:http://www.ruanyifeng.com/blog/2017/08/elastics ...
- Elastic Search快速上手(2):将数据存入ES
前言 在上手使用前,需要先了解一些基本的概念. 推荐 可以到 https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.htm ...
- Elastic Search快速上手(1):简介及安装配置
前言 最近开始尝试学习Elastic Search,因此决定做一些简单的整理,以供后续参考,快速上手使用ES. 简介 ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多 ...
- SpringMVC项目使用elastic search搜索
项目需要,引入了elastic search(后续简称es),后面将介绍本地对es的安装,使用以及java连接es查询的整个过程. 1.es索引字段建立与修改,以curl新增一个索引字段示例 curl ...
- 教你用Elastic Search:运行第一条Hello World搜索命令
摘要:Elastic Search可实时对数据库进行全文检索.处理同义词.从同样的数据中生成分析和聚合数据. 本文分享自华为云社区<Elastic Search入门(一): 简介,安装,运行第一 ...
- docker安装elastic search和kibana
安装目标 使用docker安装elastic search和kibana,版本均为7.17.1 安装es 1. docker pull 去dockerhub看具体版本,这里用7.17.1 docker ...
随机推荐
- 生成ID模板:年月日时分秒+6位自增码
因为生成订单ID.商品ID 或者什么什么ID的,不想用自增,又怕反复,于是就用 年与日时分秒 + 6位自增码 (共计20位长度)来当作ID 注意:假设你的ID是Long型.就要注意,Long的最大长 ...
- python学习之range()和xrange()
在python2中,xrange()返回一个xrange对象,注意这个对象并不是生成器,也不是迭代器,但是是迭代对象. 而range()则返回列表对象. >>> range(10) ...
- iptables常用规则:屏蔽IP地址、禁用ping、协议设置、NAT与转发、负载平衡、自定义链
iptables常用规则:屏蔽IP地址.禁用ping.协议设置.NAT与转发.负载平衡.自定义链 时间 -- :: IT社区推荐资讯 原文 http://itindex.net/detail/4772 ...
- 如何使用Photoshop(PS)将图片的底色变为透明
很多时候需要将一张图片的底色变得透明.本文描述了使用PS将图片的一部分变得透明的方法.本例将一段艺术字的背景去掉,将背景透明的文字单独保存成图片,这样以后将这段文字粘贴到其他素材上的时候,就不用担心它 ...
- Windows自带的端口转发工具netsh使用方法
微软Windows的netsh是一个命令行脚本实用工具.使用netsh工具 ,可以查看或更改本地计算机或远程计算机的网络配置.不仅可以在本地计算机上运行这些命令,而且可以在网络上的远程计算机上运行. ...
- 在Ubuntu中安装mongodb
# 下载密钥文件 sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 gpg: 下载密钥‘7F0CEB ...
- Fly (From Wikipedia)
True flies are insects of the order Diptera, the name being derived from the Greek δι- di- "two ...
- How to convert from BufferedImage to JavaFX 2.2 Image
http://blog.idrsolutions.com/2012/11/convert-bufferedimage-to-javafx-image/ ———————————————————————— ...
- COCOS2D-HTML5 开发之二】cocos2d-html5项目定义成员,局部变量,函数笔记随笔
本站文章均为李华明Himi原创,转载务必在明显处注明:(作者新浪微博:@李华明Himi) 转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/cocos2d- ...
- 使用Array的原型使对象具有length,和数组的内容
var elems = { length: , add: function (elem) { Array.prototype.push.call(this, elem); }, gather: fun ...