刚刚在过去一小时内下载并安装了elasticsearch 1.3.2
打开IP表到端口9200和9300:9400
在/ etc/hosts中设置我的计算机名称和IP
头部模块和护理人员安装并顺利运行
curhost on localhost工作完美无缺
将所有jar从下载复制到eclipse中,因此版本客户端相同
--Java--
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.QueryBuilders;
public class Test{
public static void main(String[] args) {
Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "elastictest").build();
TransportClient transportClient = new TransportClient(settings);
Client client = transportClient.addTransportAddress(new InetSocketTransportAddress("143.79.236.xxx",9300));//just masking ip with xxx for SO Question
try{
SearchResponse response = client.prepareSearch().setQuery(QueryBuilders.matchQuery("url", "twitter")).setSize(5).execute().actionGet();//bunch of urls indexed
String output = response.toString();
System.out.println(output);
}catch(Exception e){
e.printStackTrace();
}
client.close();
}
}
Run Code Online (Sandbox Code Playgroud)
--Output--
log4j:WARN No …Run Code Online (Sandbox Code Playgroud) 从版本2.0开始,默认情况下Elasticsearch仅在环回接口上绑定(在配置方面为_local_).
的文档说有切换到另一网络,例如一方式,_non_loopback_结合到第一非环回接口.它工作正常.
但我想不通我怎么组合这些设置,以便Elasticsearch上结合两个环回和非环回接口同时?
PS.我的理由是我在通过localhost连接到它的每个Elasticsearch实例上使用Logstash,但我也希望其他Elasticsearch实例看到彼此形成集群...
我正在使用Elasticsearch 5.2和Spring Boot 1.5.1.我通过Spring应用程序中的Java客户端连接到它.当我在端口上连接它9300或9200我得到NoNodeAvailableException: None of the configured nodes are available.在我的Java客户端中,我将client.transport.sniff属性设置为true.在端口9200上通过cURL向它发送请求时,它正常工作.我在一个集群中有4个节点,我无法连接到任何节点.我的配置文件具有network除法中的所有默认值,除了network.host它具有eth0 inet addr值.
我正在使用Gradle.我的依赖是:
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.elasticsearch:elasticsearch:5.2.0')
compile('org.elasticsearch.client:transport:5.2.0')
compile('org.apache.logging.log4j:log4j-api:2.7')
compile('org.apache.logging.log4j:log4j-core:2.7')
Run Code Online (Sandbox Code Playgroud)
我的连接到Elasticsearch集群的代码:
@Bean
public TransportClient elasticClient() {
org.elasticsearch.common.settings.Settings settings = Settings.builder()
.put("client.transport.sniff", true)
.put("cluster.name", "TestCluster")
.build();
TransportClient client = null;
try {
client = new org.elasticsearch.transport.client.PreBuiltTransportClient(settings)
.addTransportAddress(new org.elasticsearch.common.transport.InetSocketTransportAddress(
InetAddress.getByName("54.175.155.56"), 9200));
} catch (UnknownHostException e) {
e.printStackTrace();
}
return client;
}
Run Code Online (Sandbox Code Playgroud)
ES启动时的ES日志是:
[2017-02-15T10:37:40,664][INFO …Run Code Online (Sandbox Code Playgroud) Settings settings = Settings.settingsBuilder()
.put("cluster.name", "logging_elasticsearch")
.build();
TransportClient client = TransportClient.builder()
.settings(settings)
.build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByAddress(new byte[]{10,100,30,62}), 9300));
SearchResponse response = client.prepareSearch("logstash-2016.09.08")
.setTypes("type1", "type2")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.termQuery("multi", "test")) // Query
.setPostFilter(QueryBuilders.rangeQuery("age").from(12).to(18)) // Filter
.setFrom(0).setSize(60).setExplain(true)
.execute()
.actionGet();
Run Code Online (Sandbox Code Playgroud)
elasticsearch.yml
我NoNodeAvailableException在执行搜索查询时遇到了问题.
我尝试了这个解决方案:https: //stackoverflow.com/a/33875764/2616923 但它没有用.