io.searchbox.core.DocumentResult Java Examples

The following examples show how to use io.searchbox.core.DocumentResult. 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: JestClient.java    From wES with MIT License 6 votes vote down vote up
@Override
public IEsItem saveIndex(IEsItem doc) throws Exception {
	Index.Builder builder = new Index.Builder(doc);
	if (doc.getIndex() != null) {
		builder.index(doc.getIndex());
	}
	if (doc.getType() != null) {
		builder.type(doc.getType());
	}
	if (doc.getId() != null) {
		builder.id(doc.getId());
	}

	DocumentResult result = _exec(builder.build());
	if (result != null) {
		doc.setIndex(result.getIndex());
		doc.setType(result.getType());
		doc.setId(result.getId());
		return doc;
	}
	return null;
}
 
Example #2
Source File: IndexerManagerBeanTest.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void indexPartIterationTest() throws IndexerNotAvailableException, AccountNotFoundException, IndexerRequestException {
    DocumentResult documentResult = new DocumentResult(new Gson());
    PartIteration partIteration = new PartIteration();
    Mockito.when(indexManager.executeUpdate(Matchers.any(Update.Builder.class)))
            .thenReturn(documentResult);
    indexerManagerBean.indexPartIteration(partIteration);
    Mockito.verify(indexManager,times(1)).executeUpdate(Matchers.any(Update.Builder.class));

}
 
Example #3
Source File: IndexerManagerBeanTest.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void indexDocumentIterationTest() throws IndexerNotAvailableException, AccountNotFoundException, IndexerRequestException {
    DocumentResult documentResult = new DocumentResult(new Gson());
    DocumentIteration documentIteration = new DocumentIteration();
    Mockito.when(indexManager.executeUpdate(Matchers.any(Update.Builder.class)))
        .thenReturn(documentResult);
    indexerManagerBean.indexDocumentIteration(documentIteration);
    Mockito.verify(indexManager,times(1)).executeUpdate(Matchers.any(Update.Builder.class));

}
 
Example #4
Source File: JestClient.java    From wES with MIT License 5 votes vote down vote up
@Override
public boolean delete(IEsItem doc) throws Exception {
	Delete.Builder builder = new Delete.Builder(doc.getId());
	if (doc.getIndex() != null) {
		builder.index(doc.getIndex());
	}
	if (doc.getType() != null) {
		builder.type(doc.getType());
	}
	DocumentResult result = _exec(builder.build());
	if (result != null) {
		return true;
	}
	return false;
}
 
Example #5
Source File: BufferedHttpFailedItemOps.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public FailedItemSource createItem(AbstractDocumentTargetedAction<DocumentResult> failed) {
    BufferedIndex failedRequest = (BufferedIndex) failed;
    if (failedRequest.getSource() instanceof FailedItemSource) {
        LOG.trace("Reusing {}", FailedItemSource.class.getSimpleName());
        return (FailedItemSource) failedRequest.getSource();
    }
    return new FailedItemSource<>(failedRequest.getSource(), createInfo(failed));
}
 
Example #6
Source File: JestClient.java    From wES with MIT License 5 votes vote down vote up
@Override
public IEsItem get(IEsItem doc) throws Exception {
	Get.Builder builder = new Get.Builder(doc.getIndex(), doc.getId());
	if (doc.getType() != null) {
		builder.type(doc.getType());
	}
	DocumentResult result = _exec(builder.build());
	if (result != null) {
		return result.getSourceAsObject(doc.getClass());
	}
	return null;
}
 
Example #7
Source File: JestHttpFailedItemOps.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public FailedItemSource createItem(AbstractDocumentTargetedAction<DocumentResult> failedItem) {
    FailedItemInfo failedItemInfo = createInfo(failedItem);
    return new FailedItemSource<>(
            new StringItemSource((String) itemIntrospector.getPayload(failedItem)), failedItemInfo
    );
}
 
Example #8
Source File: JestActionIntrospectorTest.java    From log4j2-elasticsearch with Apache License 2.0 5 votes vote down vote up
@Test
public void intropectorCanAccessActionPayload() {

    // given
    BatchItemIntrospector<AbstractDocumentTargetedAction<DocumentResult>> introspector = new JestActionIntrospector();
    String testPayload = "testPayload";
    AbstractDocumentTargetedAction<DocumentResult> action = new Index.Builder(testPayload).build();

    // when
    String payload = (String) introspector.getPayload(action);

    // then
    Assert.assertEquals(testPayload, payload);
}
 
Example #9
Source File: JestActionIntrospector.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public String getPayload(AbstractDocumentTargetedAction<DocumentResult> introspected) {
    return (String) introspected.payload;
}
 
Example #10
Source File: BufferedHttpFailedItemOpsTest.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
public AbstractDocumentTargetedAction<DocumentResult> createDefaultTestIndexRequest(ItemSource<ByteBuf> itemSource, String expectedIndex) {
    return new BufferedIndex.Builder(itemSource)
            .type(UUID.randomUUID().toString())
            .index(expectedIndex)
            .build();
}
 
Example #11
Source File: JestHttpFailedItemOpsTest.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
public AbstractDocumentTargetedAction<DocumentResult> createDefaultTestIndexRequest(ItemSource<String> itemSource, String expectedIndex) {
    return new Index.Builder(itemSource.getSource())
            .type(UUID.randomUUID().toString())
            .index(expectedIndex)
            .build();
}
 
Example #12
Source File: BufferedJestHttpObjectFactory.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
protected FailedItemOps<AbstractDocumentTargetedAction<DocumentResult>> failedItemOps() {
    return new BufferedHttpFailedItemOps();
}
 
Example #13
Source File: JestHttpFailedItemOps.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public FailedItemInfo createInfo(AbstractDocumentTargetedAction<DocumentResult> failed) {
    return new FailedItemInfo(failed.getIndex());
}
 
Example #14
Source File: BufferedHttpFailedItemOps.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public FailedItemInfo createInfo(
        AbstractDocumentTargetedAction<DocumentResult> failed
) {
    return new FailedItemInfo(failed.getIndex());
}
 
Example #15
Source File: BufferedIndex.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public DocumentResult createNewElasticSearchResult(String responseBody, int statusCode, String reasonPhrase, Gson gson) {
    throw new UnsupportedOperationException("BufferedIndex cannot handle String result. Use buffer-based API");
}
 
Example #16
Source File: JestHttpObjectFactory.java    From log4j2-elasticsearch with Apache License 2.0 4 votes vote down vote up
protected FailedItemOps<AbstractDocumentTargetedAction<DocumentResult>> failedItemOps() {
    return new JestHttpFailedItemOps();
}
 
Example #17
Source File: JestTest.java    From springBoot-study with Apache License 2.0 2 votes vote down vote up
/**
* 删除数据
* @param indexName
* @param typeName
* @param id
* @return
* @throws Exception
*/
public boolean delete(JestClient jestClient,String indexName, String typeName, String id) throws Exception {  
    DocumentResult dr = jestClient.execute(new Delete.Builder(id).index(indexName).type(typeName).build());  
    return dr.isSucceeded();  
}
 
Example #18
Source File: JestTest.java    From java-study with Apache License 2.0 2 votes vote down vote up
/**
* 删除数据
* @param indexName
* @param typeName
* @param id
* @return
* @throws Exception
*/
public boolean delete(JestClient jestClient,String indexName, String typeName, String id) throws Exception {  
    DocumentResult dr = jestClient.execute(new Delete.Builder(id).index(indexName).type(typeName).build());  
    return dr.isSucceeded();  
}