Search in sources :

Example 6 with MultiGetRequestBuilder

use of org.elasticsearch.action.get.MultiGetRequestBuilder in project sonarqube by SonarSource.

the class ProxyMultiGetRequestBuilderTest method trace_logs.

@Test
public void trace_logs() {
    logTester.setLevel(LoggerLevel.TRACE);
    MultiGetRequestBuilder request = esTester.client().prepareMultiGet();
    request.add(new MultiGetRequest.Item(FakeIndexDefinition.INDEX, FakeIndexDefinition.TYPE, "ruleKey").fetchSourceContext(FetchSourceContext.FETCH_SOURCE));
    request.get();
    assertThat(logTester.logs(LoggerLevel.TRACE)).hasSize(1);
}
Also used : MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) Test(org.junit.Test)

Example 7 with MultiGetRequestBuilder

use of org.elasticsearch.action.get.MultiGetRequestBuilder in project play2-elasticsearch by cleverage.

the class IndexService method multiGet.

/**
     * Get Indexable Object for an Id
     *
     * @param indexPath
     * @param clazz
     * @return
     */
public static <T extends Index> List<T> multiGet(IndexQueryPath indexPath, Class<T> clazz, Collection<String> ids) {
    MultiGetRequestBuilder multiGetRequestBuilder = getMultiGetRequestBuilder(indexPath, ids);
    MultiGetResponse multiGetResponse = multiGetRequestBuilder.execute().actionGet();
    return getTsFromMultiGetResponse(clazz, multiGetResponse);
}
Also used : MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder)

Example 8 with MultiGetRequestBuilder

use of org.elasticsearch.action.get.MultiGetRequestBuilder in project play2-elasticsearch by cleverage.

the class IndexService method multiGet.

/**
     * Get a response for a simple request
     * @param indexName
     * @param indexType
     * @param ids
     * @return
     */
public static MultiGetResponse multiGet(String indexName, String indexType, Collection<String> ids) {
    MultiGetRequestBuilder multiGetRequestBuilder = IndexClient.client.prepareMultiGet();
    for (String id : ids) {
        multiGetRequestBuilder.add(indexName, indexType, ids);
    }
    MultiGetResponse multiGetResponse = multiGetRequestBuilder.execute().actionGet();
    return multiGetResponse;
}
Also used : MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder)

Example 9 with MultiGetRequestBuilder

use of org.elasticsearch.action.get.MultiGetRequestBuilder in project play2-elasticsearch by cleverage.

the class IndexService method multiGetAsync.

/**
     * Get Indexable Object for an Ids asynchronously
     * @param indexPath
     * @param clazz
     * @param ids
     * @param List<T>
     * @return
     */
public static <T extends Index> F.Promise<List<T>> multiGetAsync(IndexQueryPath indexPath, final Class<T> clazz, Collection<String> ids) {
    MultiGetRequestBuilder multiGetRequestBuilder = getMultiGetRequestBuilder(indexPath, ids);
    F.Promise<MultiGetResponse> responsePromise = AsyncUtils.executeAsyncJava(multiGetRequestBuilder);
    return responsePromise.filter(null).map(new F.Function<MultiGetResponse, List<T>>() {

        public List<T> apply(MultiGetResponse getResponse) {
            return getTsFromMultiGetResponse(clazz, getResponse);
        }
    });
}
Also used : MultiGetResponse(org.elasticsearch.action.get.MultiGetResponse) MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) F(play.libs.F) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with MultiGetRequestBuilder

use of org.elasticsearch.action.get.MultiGetRequestBuilder in project elasticsearch by elastic.

the class BulkProcessorIT method testBulkProcessorWaitOnClose.

public void testBulkProcessorWaitOnClose() throws Exception {
    BulkProcessorTestListener listener = new BulkProcessorTestListener();
    int numDocs = randomIntBetween(10, 100);
    BulkProcessor processor = BulkProcessor.builder(client(), listener).setName("foo").setConcurrentRequests(randomIntBetween(0, 1)).setBulkActions(numDocs).setFlushInterval(TimeValue.timeValueHours(24)).setBulkSize(new ByteSizeValue(randomIntBetween(1, 10), RandomPicks.randomFrom(random(), ByteSizeUnit.values()))).build();
    MultiGetRequestBuilder multiGetRequestBuilder = indexDocs(client(), processor, numDocs);
    assertThat(processor.isOpen(), is(true));
    assertThat(processor.awaitClose(1, TimeUnit.MINUTES), is(true));
    if (randomBoolean()) {
        // check if we can call it multiple times
        if (randomBoolean()) {
            assertThat(processor.awaitClose(1, TimeUnit.MINUTES), is(true));
        } else {
            processor.close();
        }
    }
    assertThat(processor.isOpen(), is(false));
    assertThat(listener.beforeCounts.get(), greaterThanOrEqualTo(1));
    assertThat(listener.afterCounts.get(), greaterThanOrEqualTo(1));
    assertThat(listener.bulkFailures.size(), equalTo(0));
    assertResponseItems(listener.bulkItems, numDocs);
    assertMultiGetResponse(multiGetRequestBuilder.get(), numDocs);
}
Also used : MultiGetRequestBuilder(org.elasticsearch.action.get.MultiGetRequestBuilder) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue)

Aggregations

MultiGetRequestBuilder (org.elasticsearch.action.get.MultiGetRequestBuilder)13 MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)5 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 HashSet (java.util.HashSet)2 IndexRequest (org.elasticsearch.action.index.IndexRequest)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Alias (org.elasticsearch.action.admin.indices.alias.Alias)1 MultiGetItemResponse (org.elasticsearch.action.get.MultiGetItemResponse)1 MultiGetRequest (org.elasticsearch.action.get.MultiGetRequest)1 BytesArray (org.elasticsearch.common.bytes.BytesArray)1 BytesReference (org.elasticsearch.common.bytes.BytesReference)1 FetchSourceContext (org.elasticsearch.search.fetch.subphase.FetchSourceContext)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 F (play.libs.F)1