Search in sources :

Example 66 with IndexResponse

use of org.elasticsearch.action.index.IndexResponse in project elasticsearch by elastic.

the class ContextCompletionSuggestSearchIT method testContextFilteringWorksWithUTF8Categories.

public void testContextFilteringWorksWithUTF8Categories() throws Exception {
    CategoryContextMapping contextMapping = ContextBuilder.category("cat").field("cat").build();
    LinkedHashMap<String, ContextMapping> map = new LinkedHashMap<>(Collections.singletonMap("cat", contextMapping));
    final CompletionMappingBuilder mapping = new CompletionMappingBuilder().context(map);
    createIndexAndMapping(mapping);
    IndexResponse indexResponse = client().prepareIndex(INDEX, TYPE, "1").setSource(jsonBuilder().startObject().startObject(FIELD).field("input", "suggestion").endObject().field("cat", "ctx\\u00e4").endObject()).get();
    assertThat(indexResponse.status(), equalTo(RestStatus.CREATED));
    assertNoFailures(client().admin().indices().prepareRefresh(INDEX).get());
    CompletionSuggestionBuilder contextSuggestQuery = SuggestBuilders.completionSuggestion(FIELD).prefix("sugg").contexts(Collections.singletonMap("cat", Collections.singletonList(CategoryQueryContext.builder().setCategory("ctx\\u00e4").build())));
    assertSuggestions("foo", contextSuggestQuery, "suggestion");
}
Also used : CompletionSuggestionBuilder(org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder) GeoContextMapping(org.elasticsearch.search.suggest.completion.context.GeoContextMapping) ContextMapping(org.elasticsearch.search.suggest.completion.context.ContextMapping) CategoryContextMapping(org.elasticsearch.search.suggest.completion.context.CategoryContextMapping) IndexResponse(org.elasticsearch.action.index.IndexResponse) CompletionMappingBuilder(org.elasticsearch.search.suggest.CompletionSuggestSearchIT.CompletionMappingBuilder) CategoryContextMapping(org.elasticsearch.search.suggest.completion.context.CategoryContextMapping) LinkedHashMap(java.util.LinkedHashMap)

Example 67 with IndexResponse

use of org.elasticsearch.action.index.IndexResponse in project elasticsearch by elastic.

the class FieldStatsProviderRefreshTests method indexDocument.

private void indexDocument(String id, String sValue) {
    IndexResponse response = client().prepareIndex("index", "type", id).setSource("s", sValue).get();
    assertThat(response.status(), anyOf(equalTo(RestStatus.OK), equalTo(RestStatus.CREATED)));
}
Also used : IndexResponse(org.elasticsearch.action.index.IndexResponse)

Example 68 with IndexResponse

use of org.elasticsearch.action.index.IndexResponse in project elasticsearch by elastic.

the class IndexActionIT method testCreatedFlagWithExternalVersioning.

public void testCreatedFlagWithExternalVersioning() throws Exception {
    createIndex("test");
    ensureGreen();
    IndexResponse indexResponse = client().prepareIndex("test", "type", "1").setSource("field1", "value1_1").setVersion(123).setVersionType(VersionType.EXTERNAL).execute().actionGet();
    assertEquals(DocWriteResponse.Result.CREATED, indexResponse.getResult());
}
Also used : IndexResponse(org.elasticsearch.action.index.IndexResponse)

Example 69 with IndexResponse

use of org.elasticsearch.action.index.IndexResponse in project elasticsearch by elastic.

the class IndexActionIT method testCreatedFlagParallelExecution.

public void testCreatedFlagParallelExecution() throws Exception {
    createIndex("test");
    ensureGreen();
    int threadCount = 20;
    final int docCount = 300;
    int taskCount = docCount * threadCount;
    final AtomicIntegerArray createdCounts = new AtomicIntegerArray(docCount);
    ExecutorService threadPool = Executors.newFixedThreadPool(threadCount);
    List<Callable<Void>> tasks = new ArrayList<>(taskCount);
    final Random random = random();
    for (int i = 0; i < taskCount; i++) {
        tasks.add(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                int docId = random.nextInt(docCount);
                IndexResponse indexResponse = index("test", "type", Integer.toString(docId), "field1", "value");
                if (indexResponse.getResult() == DocWriteResponse.Result.CREATED) {
                    createdCounts.incrementAndGet(docId);
                }
                return null;
            }
        });
    }
    threadPool.invokeAll(tasks);
    for (int i = 0; i < docCount; i++) {
        assertThat(createdCounts.get(i), lessThanOrEqualTo(1));
    }
    terminate(threadPool);
}
Also used : AtomicIntegerArray(java.util.concurrent.atomic.AtomicIntegerArray) Random(java.util.Random) IndexResponse(org.elasticsearch.action.index.IndexResponse) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) InvalidIndexNameException(org.elasticsearch.indices.InvalidIndexNameException)

Example 70 with IndexResponse

use of org.elasticsearch.action.index.IndexResponse in project elasticsearch by elastic.

the class IndexActionIT method testCreateFlagWithBulk.

public void testCreateFlagWithBulk() {
    createIndex("test");
    ensureGreen();
    BulkResponse bulkResponse = client().prepareBulk().add(client().prepareIndex("test", "type", "1").setSource("field1", "value1_1")).execute().actionGet();
    assertThat(bulkResponse.hasFailures(), equalTo(false));
    assertThat(bulkResponse.getItems().length, equalTo(1));
    IndexResponse indexResponse = bulkResponse.getItems()[0].getResponse();
    assertEquals(DocWriteResponse.Result.CREATED, indexResponse.getResult());
}
Also used : IndexResponse(org.elasticsearch.action.index.IndexResponse) BulkResponse(org.elasticsearch.action.bulk.BulkResponse)

Aggregations

IndexResponse (org.elasticsearch.action.index.IndexResponse)103 Test (org.junit.Test)26 SearchResponse (org.elasticsearch.action.search.SearchResponse)18 IOException (java.io.IOException)15 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)15 HashMap (java.util.HashMap)13 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)13 IndexRequest (org.elasticsearch.action.index.IndexRequest)13 ElasticsearchException (org.elasticsearch.ElasticsearchException)11 CountDownLatch (java.util.concurrent.CountDownLatch)10 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)8 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)7 Settings (org.elasticsearch.common.settings.Settings)7 ArrayList (java.util.ArrayList)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)6 ExecutionException (java.util.concurrent.ExecutionException)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)5