mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-19 10:32:10 +00:00
parent
9a6172b4fe
commit
d22b12874d
@ -27,10 +27,13 @@ import org.springframework.data.repository.NoRepositoryBean;
|
|||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Sascha Woo
|
* @author Sascha Woo
|
||||||
|
* @author Murali Chevuri
|
||||||
*/
|
*/
|
||||||
@NoRepositoryBean
|
@NoRepositoryBean
|
||||||
public interface ElasticsearchRepository<T, ID> extends ElasticsearchCrudRepository<T, ID> {
|
public interface ElasticsearchRepository<T, ID> extends ElasticsearchCrudRepository<T, ID> {
|
||||||
|
|
||||||
|
<S extends T> S indexWithoutRefresh(S entity);
|
||||||
|
|
||||||
<S extends T> S index(S entity);
|
<S extends T> S index(S entity);
|
||||||
|
|
||||||
Iterable<T> search(QueryBuilder query);
|
Iterable<T> search(QueryBuilder query);
|
||||||
|
@ -56,9 +56,9 @@ import org.springframework.util.Assert;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Michael Wirth
|
* @author Michael Wirth
|
||||||
* @author Sascha Woo
|
* @author Sascha Woo
|
||||||
|
* @author Murali Chevuri
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractElasticsearchRepository<T, ID>
|
public abstract class AbstractElasticsearchRepository<T, ID> implements ElasticsearchRepository<T, ID> {
|
||||||
implements ElasticsearchRepository<T, ID> {
|
|
||||||
|
|
||||||
static final Logger LOGGER = LoggerFactory.getLogger(AbstractElasticsearchRepository.class);
|
static final Logger LOGGER = LoggerFactory.getLogger(AbstractElasticsearchRepository.class);
|
||||||
protected ElasticsearchOperations elasticsearchOperations;
|
protected ElasticsearchOperations elasticsearchOperations;
|
||||||
@ -88,7 +88,7 @@ public abstract class AbstractElasticsearchRepository<T, ID>
|
|||||||
putMapping();
|
putMapping();
|
||||||
}
|
}
|
||||||
} catch (ElasticsearchException exception) {
|
} catch (ElasticsearchException exception) {
|
||||||
LOGGER.error("failed to load elasticsearch nodes : " + exception.getDetailedMessage());
|
LOGGER.error("failed to load elasticsearch nodes : {}", exception.getDetailedMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,6 +175,17 @@ public abstract class AbstractElasticsearchRepository<T, ID>
|
|||||||
return save(entity);
|
return save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method might lead to a temporary inconsistent state until
|
||||||
|
* {@link org.springframework.data.elasticsearch.repository.ElasticsearchRepository#refresh() refresh} is called.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public <S extends T> S indexWithoutRefresh(S entity) {
|
||||||
|
Assert.notNull(entity, "Cannot save 'null' entity.");
|
||||||
|
elasticsearchOperations.index(createIndexQuery(entity));
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <S extends T> Iterable<S> saveAll(Iterable<S> entities) {
|
public <S extends T> Iterable<S> saveAll(Iterable<S> entities) {
|
||||||
Assert.notNull(entities, "Cannot insert 'null' as a List.");
|
Assert.notNull(entities, "Cannot insert 'null' as a List.");
|
||||||
|
@ -60,6 +60,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Michael Wirth
|
* @author Michael Wirth
|
||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
|
* @author Murali Chevuri
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration("classpath:/simple-repository-test.xml")
|
@ContextConfiguration("classpath:/simple-repository-test.xml")
|
||||||
@ -569,6 +570,27 @@ public class SimpleElasticsearchRepositoryTests {
|
|||||||
assertThat(entities.getTotalElements()).isEqualTo(1L);
|
assertThat(entities.getTotalElements()).isEqualTo(1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldIndexWithoutRefreshEntity() {
|
||||||
|
|
||||||
|
// given
|
||||||
|
String documentId = randomNumeric(5);
|
||||||
|
SampleEntity sampleEntity = new SampleEntity();
|
||||||
|
sampleEntity.setId(documentId);
|
||||||
|
sampleEntity.setVersion(System.currentTimeMillis());
|
||||||
|
sampleEntity.setMessage("some message");
|
||||||
|
|
||||||
|
// when
|
||||||
|
repository.indexWithoutRefresh(sampleEntity);
|
||||||
|
|
||||||
|
// then
|
||||||
|
Page<SampleEntity> entities = repository.search(termQuery("id", documentId), PageRequest.of(0, 50));
|
||||||
|
assertThat(entities.getTotalElements()).isEqualTo(0L);
|
||||||
|
repository.refresh();
|
||||||
|
entities = repository.search(termQuery("id", documentId), PageRequest.of(0, 50));
|
||||||
|
assertThat(entities.getTotalElements()).isEqualTo(1L);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldSortByGivenField() {
|
public void shouldSortByGivenField() {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user