Java Elastic Search API: невозможно запустить простой пример: org.elasticsearch.transport.NodeDisconnectedException: - PullRequest
0 голосов
/ 29 октября 2018

Я скачал бинарные файлы поиска с https://www.elastic.co/downloads/elasticsearch и все работает нормально.

Теперь: я пытаюсь запустить простой пример ниже:

Я впервые запустил сервер bin/elasticsearch и запустил код ниже

package jp.gr.java_conf.uzresk.es.search;

import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.FilterBuilders;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHits;

public class Search {

    public static void main(String[] args) {

        new Search().run();
    }

    public void run() {
        Client client = null;
        TransportClient transportClient = null;
        try {
            transportClient = new TransportClient();
            client = transportClient.addTransportAddress(new InetSocketTransportAddress("192.168.1.40", 9300));

            SearchResponse response = client.prepareSearch("tms-allflat").setTypes("personal")
                    .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
                    .setQuery(QueryBuilders.termQuery("skill_1", "Java"))
                    .setPostFilter(FilterBuilders.rangeFilter("age").from(25).to(30)).setFrom(0).setSize(10)
                    .setExplain(true).execute().actionGet();

            SearchHits hits = response.getHits();
            hits.forEach(s -> System.out.println(s.getSourceAsString()));

        } finally {
            transportClient.close();
            client.close();
        }
    }
}

Трассировка была выбрана так:

Oct 28, 2018 11:15:52 PM org.elasticsearch.plugins.PluginsService <init>
INFO: [Achelous] loaded [], sites []
Oct 28, 2018 11:15:53 PM org.elasticsearch.client.transport.TransportClientNodesService$SimpleNodeSampler doSample
INFO: [Achelous] failed to get node info for [#transport#-1][dell-Inspiron-7577][inet[localhost/127.0.0.1:9300]], disconnecting...
org.elasticsearch.transport.NodeDisconnectedException: [][inet[localhost/127.0.0.1:9300]][cluster:monitor/nodes/info] disconnected

Exception in thread "main" org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []
    at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:305)
    at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:200)
    at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)
    at org.elasticsearch.client.support.AbstractClient.search(AbstractClient.java:338)
    at org.elasticsearch.client.transport.TransportClient.search(TransportClient.java:430)
    at org.elasticsearch.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:1112)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65)
    at jp.gr.java_conf.uzresk.es.search.Search.run(Search.java:30)
    at jp.gr.java_conf.uzresk.es.search.Search.main(Search.java:16)

Репозиторий Github, со всеми отделами, можно найти здесь: https://github.com/uzresk/elasticsearch-javaapi-examples

[1] Что я делаю не так?

[2] Как это исправить?

Я попытался погуглить, но не нашел ничего перспективного - мне бы понравился указатель или два в правильном направлении. :)

РЕДАКТИРОВАТЬ: Мойasticsearch.yml это:

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

Ответы [ 2 ]

0 голосов
/ 29 октября 2018

Отредактируйте ваш файлasticsearch.yml добавьте ниже настройки и затем перезапустите сервер.

network.host: 192.168.1.40

Список хостов по умолчанию: ["127.0.0.1", "[:: 1]"]. Вам нужно указать свой хост, если он отличается от 127.0.0.1.

0 голосов
/ 29 октября 2018

Измените порт на 9200 с 9300, как показано ниже:

try {
            transportClient = new TransportClient();
            client = transportClient.addTransportAddress(new InetSocketTransportAddress("192.168.1.40", 9200))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...