Package org.elasticsearch

Examples of org.elasticsearch.ElasticsearchException$WithRestHeaders


    public ShardSuggestResponse suggest(ShardSuggestRequest shardSuggestRequest) {
        List<String> suggestions;
        try {
            suggestions = Lists.newArrayList(getSuggestions(shardSuggestRequest));
        } catch (IOException e) {
            throw new ElasticsearchException("Error getting suggestions", e);
        }
        return new ShardSuggestResponse(shardId.index().name(), shardId.id(), suggestions);
    }
View Full Code Here


            queryAnalyzer = fieldMapper.searchAnalyzer();
            if (Strings.hasLength(fieldType.indexAnalyzer())) {
                NamedAnalyzer namedAnalyzer = analysisService.analyzer(fieldType.queryAnalyzer());
                if (namedAnalyzer == null) {
                    throw new ElasticsearchException("Query analyzer[" + fieldType.queryAnalyzer() + "] does not exist.");
                }
                queryAnalyzer = namedAnalyzer.analyzer();
            }

            indexAnalyzer = fieldMapper.searchAnalyzer();
            if (Strings.hasLength(fieldType.indexAnalyzer())) {
                NamedAnalyzer namedAnalyzer = analysisService.analyzer(fieldType.indexAnalyzer());
                if (namedAnalyzer == null) {
                    throw new ElasticsearchException("Index analyzer[" + fieldType.indexAnalyzer() + "] does not exist.");
                }
                indexAnalyzer = namedAnalyzer.analyzer();
            }
        }
View Full Code Here

      logger.debug("Sysinfo River {} found on this node, go to call mgm operation on it {}", req.getRiverName(), req);
      try {
        return performOperationOnRiver(river, req, clusterService.localNode());
      } catch (Exception e) {
        logger.error("Exception from river management operation: {}", e, e.getMessage());
        throw new ElasticsearchException(e.getMessage(), e);
      }
    }
  }
View Full Code Here

                    }
                }
            }
            return new ShardTermlistResponse(request.index(), request.shardId(), map);
        } catch (IOException ex) {
            throw new ElasticsearchException(ex.getMessage(), ex);
        } finally {
            searcher.close();
        }
    }
View Full Code Here

    public HttpClient(String hostname, Integer port) {
        try {
            baseUrl = new URL("http", hostname, port, "/");
        } catch (MalformedURLException e) {
            throw new ElasticsearchException("", e);
        }
    }
View Full Code Here

    public HttpClientResponse request(String method, String path, Map<String, String> headers, String payload) {
        URL url;
        try {
            url = new URL(baseUrl, path);
        } catch (MalformedURLException e) {
            throw new ElasticsearchException("Cannot parse " + path, e);
        }

        HttpURLConnection urlConnection;
        try {
            urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setRequestMethod(method);
            if (headers != null) {
                for (Map.Entry<String, String> headerEntry : headers.entrySet()) {
                    urlConnection.setRequestProperty(headerEntry.getKey(), headerEntry.getValue());
                }
            }

            if (payload != null) {
                urlConnection.setDoOutput(true);
                urlConnection.setRequestProperty("Content-Type", "application/json");
                urlConnection.setRequestProperty("Accept", "application/json");
                OutputStreamWriter osw = new OutputStreamWriter(urlConnection.getOutputStream());
                osw.write(payload);
                osw.flush();
                osw.close();
            }

            urlConnection.connect();
        } catch (IOException e) {
            throw new ElasticsearchException("", e);
        }

        int errorCode = -1;
        Map<String, List<String>> respHeaders = null;
        try {
            errorCode = urlConnection.getResponseCode();
            respHeaders = urlConnection.getHeaderFields();
            InputStream inputStream = urlConnection.getInputStream();
            String body = null;
            try {
                body = Streams.copyToString(new InputStreamReader(inputStream, Charsets.UTF_8));
            } catch (IOException e1) {
                throw new ElasticsearchException("problem reading error stream", e1);
            }
            return new HttpClientResponse(body, errorCode, respHeaders, null);
        } catch (IOException e) {
            InputStream errStream = urlConnection.getErrorStream();
            String body = null;
            if (errStream != null) {
                try {
                    body = Streams.copyToString(new InputStreamReader(errStream, Charsets.UTF_8));
                } catch (IOException e1) {
                    throw new ElasticsearchException("problem reading error stream", e1);
                }
            }
            return new HttpClientResponse(body, errorCode, respHeaders, e);
        } finally {
            urlConnection.disconnect();
View Full Code Here

  @Bean
  public Client elasticsearch() {
    Client mockClient = Mockito.mock(Client.class);

    Mockito.when(mockClient.prepareSearch(Matchers.anyString())).thenThrow(new ElasticsearchException("no ES here"));

    return mockClient;
  }
View Full Code Here

    // Setup
    DeleteRequestBuilder deleteRequestBuilder = mock(DeleteRequestBuilder.class);
    when(clientMocked.prepareDelete(any(String.class), any(String.class), any(String.class))).thenReturn(deleteRequestBuilder);
    ListenableActionFuture<DeleteResponse> listenableActionFutureMocked = mock(ListenableActionFuture.class);
    when(deleteRequestBuilder.execute()).thenReturn(listenableActionFutureMocked);
    when(listenableActionFutureMocked.actionGet()).thenThrow(new ElasticsearchException("Simulated exception"));

    // Action
    entityDao.delete(ESNode.class, 1l);
  }
View Full Code Here

                            }
                        }
                    }
                    if (server == null) {
                        logger.error("Cannot find server with id [{}] in configuration files [{}]", jettyConfigServerId, jettyConfig);
                        lastException.set(new ElasticsearchException("Cannot find server with id " + jettyConfigServerId));
                        return true;
                    }

                    // Keep it for now for backward compatibility with previous versions of jetty.xml
                    server.setAttribute(TRANSPORT_ATTRIBUTE, JettyHttpServerTransport.this);
View Full Code Here

    protected void doStop() throws ElasticsearchException {
        if (jettyServer != null) {
            try {
                jettyServer.stop();
            } catch (Exception ex) {
                throw new ElasticsearchException("Cannot stop jetty server", ex);
            }
            jettyServer = null;
        }
    }
View Full Code Here

TOP

Related Classes of org.elasticsearch.ElasticsearchException$WithRestHeaders

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.