本文整理汇总了Java中org.elasticsearch.action.ListenableActionFuture类的典型用法代码示例。如果您正苦于以下问题:Java ListenableActionFuture类的具体用法?Java ListenableActionFuture怎么用?Java ListenableActionFuture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ListenableActionFuture类属于org.elasticsearch.action包,在下文中一共展示了ListenableActionFuture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCancellationDuringQueryPhase
import org.elasticsearch.action.ListenableActionFuture; //导入依赖的package包/类
public void testCancellationDuringQueryPhase() throws Exception {
List<ScriptedBlockPlugin> plugins = initBlockFactory();
indexTestData();
logger.info("Executing search");
ListenableActionFuture<SearchResponse> searchResponse = client().prepareSearch("test").setQuery(
scriptQuery(new Script(
ScriptType.INLINE, "native", NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, Collections.emptyMap())))
.execute();
awaitForBlock(plugins);
cancelSearch(SearchAction.NAME);
disableBlocks(plugins);
logger.info("Segments {}", XContentHelper.toString(client().admin().indices().prepareSegments("test").get(), FORMAT_PARAMS));
ensureSearchWasCancelled(searchResponse);
}
示例2: testCancellationDuringFetchPhase
import org.elasticsearch.action.ListenableActionFuture; //导入依赖的package包/类
public void testCancellationDuringFetchPhase() throws Exception {
List<ScriptedBlockPlugin> plugins = initBlockFactory();
indexTestData();
logger.info("Executing search");
ListenableActionFuture<SearchResponse> searchResponse = client().prepareSearch("test")
.addScriptField("test_field",
new Script(ScriptType.INLINE, "native", NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, Collections.emptyMap())
).execute();
awaitForBlock(plugins);
cancelSearch(SearchAction.NAME);
disableBlocks(plugins);
logger.info("Segments {}", XContentHelper.toString(client().admin().indices().prepareSegments("test").get(), FORMAT_PARAMS));
ensureSearchWasCancelled(searchResponse);
}
示例3: testCancellationOfScrollSearches
import org.elasticsearch.action.ListenableActionFuture; //导入依赖的package包/类
public void testCancellationOfScrollSearches() throws Exception {
List<ScriptedBlockPlugin> plugins = initBlockFactory();
indexTestData();
logger.info("Executing search");
ListenableActionFuture<SearchResponse> searchResponse = client().prepareSearch("test")
.setScroll(TimeValue.timeValueSeconds(10))
.setSize(5)
.setQuery(
scriptQuery(new Script(
ScriptType.INLINE, "native", NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, Collections.emptyMap())))
.execute();
awaitForBlock(plugins);
cancelSearch(SearchAction.NAME);
disableBlocks(plugins);
SearchResponse response = ensureSearchWasCancelled(searchResponse);
if (response != null) {
// The response might not have failed on all shards - we need to clean scroll
logger.info("Cleaning scroll with id {}", response.getScrollId());
client().prepareClearScroll().addScrollId(response.getScrollId()).get();
}
}
示例4: testTasksCancellation
import org.elasticsearch.action.ListenableActionFuture; //导入依赖的package包/类
public void testTasksCancellation() throws Exception {
// Start blocking test task
// Get real client (the plugin is not registered on transport nodes)
ListenableActionFuture<TestTaskPlugin.NodesResponse> future = TestTaskPlugin.TestTaskAction.INSTANCE.newRequestBuilder(client())
.execute();
logger.info("--> started test tasks");
// Wait for the task to start on all nodes
assertBusy(() -> assertEquals(internalCluster().size(),
client().admin().cluster().prepareListTasks().setActions(TestTaskPlugin.TestTaskAction.NAME + "[n]").get().getTasks().size()));
logger.info("--> cancelling the main test task");
CancelTasksResponse cancelTasksResponse = client().admin().cluster().prepareCancelTasks()
.setActions(TestTaskPlugin.TestTaskAction.NAME).get();
assertEquals(1, cancelTasksResponse.getTasks().size());
future.get();
logger.info("--> checking that test tasks are not running");
assertEquals(0,
client().admin().cluster().prepareListTasks().setActions(TestTaskPlugin.TestTaskAction.NAME + "*").get().getTasks().size());
}
示例5: testCreateIndexStopsWaitingWhenIndexDeleted
import org.elasticsearch.action.ListenableActionFuture; //导入依赖的package包/类
public void testCreateIndexStopsWaitingWhenIndexDeleted() throws Exception {
final String indexName = "test-idx";
Settings settings = Settings.builder()
.put(indexSettings())
.put(INDEX_NUMBER_OF_SHARDS_SETTING.getKey(), randomIntBetween(1, 5))
.put(INDEX_NUMBER_OF_REPLICAS_SETTING.getKey(), internalCluster().numDataNodes() - 1)
.build();
logger.info("--> start the index creation process");
ListenableActionFuture<CreateIndexResponse> responseListener =
prepareCreate(indexName)
.setSettings(settings)
.setWaitForActiveShards(ActiveShardCount.ALL)
.execute();
logger.info("--> wait until the cluster state contains the new index");
assertBusy(() -> assertTrue(client().admin().cluster().prepareState().get().getState().metaData().hasIndex(indexName)));
logger.info("--> delete the index");
assertAcked(client().admin().indices().prepareDelete(indexName));
logger.info("--> ensure the create index request completes");
assertAcked(responseListener.get());
}
示例6: testDeleteNotFound
import org.elasticsearch.action.ListenableActionFuture; //导入依赖的package包/类
@Test
public void testDeleteNotFound() throws Exception {
String id = "1";
DeleteRequestBuilder mockDeleteRequestBuilder = mock(DeleteRequestBuilder.class);
ListenableActionFuture mockListenableActionFuture = mock(ListenableActionFuture.class);
DeleteResponse mockDeleteResponse = mock(DeleteResponse.class);
when(client.prepareDelete("steckbrief", "steckbrief", id)).thenReturn(mockDeleteRequestBuilder);
when(mockDeleteRequestBuilder.execute()).thenReturn(mockListenableActionFuture);
when(mockListenableActionFuture.actionGet()).thenReturn(mockDeleteResponse);
when(mockDeleteResponse.isFound()).thenReturn(false);
ResponseEntity response = documentController.delete(id);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
示例7: mockClient
import org.elasticsearch.action.ListenableActionFuture; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static Client mockClient(List<Map<String, Object>> dataToReturn,
SearchRequestBuilder builder) {
Client client = mock(Client.class);
InternalSearchHit[] internalHitsArr = new InternalSearchHit[dataToReturn.size()];
for (int i = 0; i < dataToReturn.size(); i++) {
Map<String, Object> data = dataToReturn.get(i);
InternalSearchHit hit = mock(InternalSearchHit.class);
internalHitsArr[i] = hit;
when(hit.getSource()).thenReturn(data);
when(hit.getId()).thenReturn(Integer.toString(i));
}
InternalSearchHits hits = new InternalSearchHits(internalHitsArr, internalHitsArr.length,
0);
SearchResponse response = mock(SearchResponse.class);
when(response.getHits()).thenReturn(hits);
ListenableActionFuture<SearchResponse> action = mock(ListenableActionFuture.class);
when(builder.execute()).thenReturn(action);
when(builder.setQuery(any(QueryBuilder.class))).thenReturn(builder);
when(action.actionGet()).thenReturn(response);
when(client.prepareSearch(anyString())).thenReturn(builder);
return client;
}
示例8: warmFieldData
import org.elasticsearch.action.ListenableActionFuture; //导入依赖的package包/类
public void warmFieldData(String parentField, String childField) {
ListenableActionFuture<SearchResponse> parentSearch = null;
ListenableActionFuture<SearchResponse> childSearch = null;
if (parentField != null) {
parentSearch = client
.prepareSearch(PARENT_INDEX)
.setQuery(matchAllQuery()).addAggregation(terms("parentfield").field(parentField)).execute();
}
if (childField != null) {
childSearch = client
.prepareSearch(CHILD_INDEX)
.setQuery(matchAllQuery()).addAggregation(terms("childfield").field(childField)).execute();
}
if (parentSearch != null) parentSearch.actionGet();
if (childSearch != null) childSearch.actionGet();
}
示例9: scrollEntries
import org.elasticsearch.action.ListenableActionFuture; //导入依赖的package包/类
protected <T> AsyncFuture<LimitedSet<T>> scrollEntries(
final Connection c, final SearchRequestBuilder request, final OptionalLimit limit,
final Function<SearchHit, T> converter
) {
final ScrollTransform<T> scrollTransform =
new ScrollTransform<T>(async, limit, converter, scrollId -> {
// Function<> that returns a Supplier
return () -> {
final ListenableActionFuture<SearchResponse> execute =
c.prepareSearchScroll(scrollId).setScroll(SCROLL_TIME).execute();
return bind(execute);
};
});
return bind(request.execute()).lazyTransform(scrollTransform);
}
示例10: bind
import org.elasticsearch.action.ListenableActionFuture; //导入依赖的package包/类
protected <T extends ActionResponse> AsyncFuture<T> bind(
final ListenableActionFuture<T> actionFuture
) {
final ResolvableFuture<T> future = async.future();
actionFuture.addListener(new ActionListener<T>() {
@Override
public void onResponse(T result) {
future.resolve(result);
}
@Override
public void onFailure(Exception e) {
future.fail(e);
}
});
return future;
}
示例11: executeProjectSearchQuery
import org.elasticsearch.action.ListenableActionFuture; //导入依赖的package包/类
private void executeProjectSearchQuery(Client client, QueryBuilder query, String type,
String routing, List<ElasticHit> elasticHits) {
SearchRequestBuilder srb = client.prepareSearch(Settings.META_INDEX);
srb = srb.setTypes(type);
srb = srb.setQuery(query);
srb = srb.addHighlightedField("name");
srb = srb.setRouting(routing);
LOG.log(Level.INFO, "Project Elastic query in Shared Dataset [{0}] is: {1} {2}", new String[]{
type, routing, srb.toString()});
ListenableActionFuture<SearchResponse> futureResponse = srb.execute();
SearchResponse response = futureResponse.actionGet();
if (response.status().getStatus() == 200) {
if (response.getHits().getHits().length > 0) {
SearchHit[] hits = response.getHits().getHits();
for (SearchHit hit : hits) {
elasticHits.add(new ElasticHit(hit));
}
}
}
}
示例12: writeToNoSQL
import org.elasticsearch.action.ListenableActionFuture; //导入依赖的package包/类
@Override
public void writeToNoSQL(List<Map<String, Object>> entityList) {
JSONArray array = JSONArray.fromObject(entityList);
for (int i = 0; i < array.size(); i++) {
IndexRequestBuilder builder = client.prepareIndex(index_name, index_type);
if (getPrimaryKey() != null)
builder.setId( ((JSONObject)array.get(i)).getString(getPrimaryKey()));
builder.setSource(array.get(i).toString());
bulkRequest.add(builder);
}
if (bulkRequest.numberOfActions() > 0) {
long t1 = System.currentTimeMillis();
ListenableActionFuture<BulkResponse> action = bulkRequest.execute();
long t2 = System.currentTimeMillis();
BulkResponse response = action.actionGet();
for (Iterator<BulkItemResponse> iterator = response.iterator(); iterator.hasNext();) {
BulkItemResponse e = (BulkItemResponse) iterator.next();
if (e.isFailed())
throw new FailedCommunicationException("Insertion to ES failed.");
}
log.info("Time taken to Write "+ bulkRequest.numberOfActions() + " documents to ES :" + ((t2-t1)) + " ms");
}
}
示例13: testMissingRequiredSearchTermsThrowsError
import org.elasticsearch.action.ListenableActionFuture; //导入依赖的package包/类
/****
* testMissingRequiredSearchTermsThrowsError
*
* Test the required params "field"
*/
public void testMissingRequiredSearchTermsThrowsError() throws Exception {
//build facet without fields param
//
TermListFacetBuilder custom_facet = new TermListFacetBuilder(facetName);
boolean thrown = false;
try {
SearchRequestBuilder srb = client().prepareSearch(index);
srb.setSearchType(SearchType.COUNT);
srb.addFacet(custom_facet);
ListenableActionFuture<SearchResponse> laf = srb.execute();
fail("Never should have gotten here: ");
} catch (Exception e) {
thrown = true;
}
assertTrue(thrown);
}
示例14: getTermList
import org.elasticsearch.action.ListenableActionFuture; //导入依赖的package包/类
/**
* getTermList
*
* @param index
* @param keyFields
* @param searchText
* @param maxPerShard
* @param prefix
* @return
*/
private SearchResponse getTermList(String index, List<String> fields, String searchText, int maxPerShard, boolean prefix, boolean caseInsensitive, boolean sort) {
TermListFacetBuilder custom_facet = new TermListFacetBuilder(facetName).fields(fields).maxPerShard(maxPerShard).prefix(prefix).sort(sort).caseInsensitive(caseInsensitive).search(searchText);
SearchResponse custom_sr = null;
try {
SearchRequestBuilder srb = client().prepareSearch(index);
srb.setSearchType(SearchType.COUNT);
srb.addFacet(custom_facet);
System.out.println("SearchRequestBuilder Facet : \n " + srb.toString() + "\n");
ListenableActionFuture<SearchResponse> laf = srb.execute();
custom_sr = laf.actionGet();
} catch (Exception e) {
e.printStackTrace(System.out);
fail("this test failed");
}
assertFalse(custom_sr.toString().startsWith("{ \"error\" : "));
System.out.println("SearchResponse : \n " + custom_sr.toString());
return custom_sr;
}
示例15: ensureSearchWasCancelled
import org.elasticsearch.action.ListenableActionFuture; //导入依赖的package包/类
private SearchResponse ensureSearchWasCancelled(ListenableActionFuture<SearchResponse> searchResponse) {
try {
SearchResponse response = searchResponse.actionGet();
logger.info("Search response {}", response);
assertNotEquals("At least one shard should have failed", 0, response.getFailedShards());
return response;
} catch (SearchPhaseExecutionException ex) {
logger.info("All shards failed with", ex);
return null;
}
}