org.elasticsearch.action.get.GetAction Java Examples

The following examples show how to use org.elasticsearch.action.get.GetAction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestFetchElasticsearch5.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected Client getTransportClient(Settings.Builder settingsBuilder, String xPackPath,
                                    String username, String password,
                                    List<InetSocketAddress> esHosts, ComponentLog log)
        throws MalformedURLException {
    TransportClient mockClient = mock(TransportClient.class);
    GetRequestBuilder getRequestBuilder = spy(new GetRequestBuilder(mockClient, GetAction.INSTANCE));
    if (exceptionToThrow != null) {
        doThrow(exceptionToThrow).when(getRequestBuilder).execute();
    } else {
        doReturn(new MockGetRequestBuilderExecutor(documentExists, esHosts.get(0))).when(getRequestBuilder).execute();
    }
    when(mockClient.prepareGet(anyString(), anyString(), anyString())).thenReturn(getRequestBuilder);

    return mockClient;
}
 
Example #2
Source File: TestFetchElasticsearch5.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
protected Client getTransportClient(Settings.Builder settingsBuilder, String xPackPath,
                                    String username, String password,
                                    List<InetSocketAddress> esHosts, ComponentLog log)
        throws MalformedURLException {
    TransportClient mockClient = mock(TransportClient.class);
    GetRequestBuilder getRequestBuilder = spy(new GetRequestBuilder(mockClient, GetAction.INSTANCE));
    if (exceptionToThrow != null) {
        doThrow(exceptionToThrow).when(getRequestBuilder).execute();
    } else {
        doReturn(new MockGetRequestBuilderExecutor(documentExists, esHosts.get(0))).when(getRequestBuilder).execute();
    }
    when(mockClient.prepareGet(anyString(), anyString(), anyString())).thenReturn(getRequestBuilder);

    return mockClient;
}
 
Example #3
Source File: TestFetchElasticsearch.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected TransportClient getTransportClient(Settings.Builder settingsBuilder, String shieldUrl,
                                             String username, String password)
        throws MalformedURLException {
    TransportClient mockClient = mock(TransportClient.class);
    GetRequestBuilder getRequestBuilder = spy(new GetRequestBuilder(mockClient, GetAction.INSTANCE));
    if (exceptionToThrow != null) {
        doThrow(exceptionToThrow).when(getRequestBuilder).execute();
    } else {
        doReturn(new MockGetRequestBuilderExecutor(documentExists)).when(getRequestBuilder).execute();
    }
    when(mockClient.prepareGet(anyString(), anyString(), anyString())).thenReturn(getRequestBuilder);

    return mockClient;
}
 
Example #4
Source File: ElasticsearchHistory.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Override
protected ElasticsearchDocumentHistory loadExistingDocumentHistory(String documentId)
    throws BaleenException {
  try {
    GetResponse response =
        new GetRequestBuilder(elasticsearch.getClient(), GetAction.INSTANCE)
            .setId(documentId)
            .setIndex(esIndex)
            .setType(esType)
            .get();

    if (!response.isExists() || response.isSourceEmpty()) {
      // If we don't have any data, then let parent implementation create a new history
      return null;
    } else {
      ESHistory esh = mapper.readValue(response.getSourceAsBytes(), ESHistory.class);
      if (esh == null) {
        return new ElasticsearchDocumentHistory(
            this, documentId, new LinkedBlockingDeque<HistoryEvent>(Collections.emptyList()));
      } else {
        return new ElasticsearchDocumentHistory(
            this, documentId, new LinkedBlockingDeque<HistoryEvent>(esh.getEvents()));
      }
    }
  } catch (IOException e) {
    throw new BaleenException(e);
  }
}
 
Example #5
Source File: TestFetchElasticsearch.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected TransportClient getTransportClient(Settings.Builder settingsBuilder, String shieldUrl,
                                             String username, String password)
        throws MalformedURLException {
    TransportClient mockClient = mock(TransportClient.class);
    GetRequestBuilder getRequestBuilder = spy(new GetRequestBuilder(mockClient, GetAction.INSTANCE));
    if (exceptionToThrow != null) {
        doThrow(exceptionToThrow).when(getRequestBuilder).execute();
    } else {
        doReturn(new MockGetRequestBuilderExecutor(documentExists)).when(getRequestBuilder).execute();
    }
    when(mockClient.prepareGet(anyString(), anyString(), anyString())).thenReturn(getRequestBuilder);

    return mockClient;
}