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");
}
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)));
}
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());
}
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);
}
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());
}
Aggregations