use of org.springframework.data.elasticsearch.core.query.IndexQuery in project spring-data-elasticsearch by spring-projects.
the class ElasticsearchTemplateCallbackTests method indexShouldInvokeAfterSaveCallbacks.
// DATAES-771
@Test
void indexShouldInvokeAfterSaveCallbacks() {
template.setEntityCallbacks(EntityCallbacks.create(afterSaveCallback));
Person entity = new Person("init", "luke");
IndexQuery indexQuery = indexQueryForEntity(entity);
template.index(indexQuery, index);
verify(afterSaveCallback).onAfterSave(eq(entity), eq(index));
Person savedPerson = (Person) indexQuery.getObject();
assertThat(savedPerson.firstname).isEqualTo("after-save");
}
use of org.springframework.data.elasticsearch.core.query.IndexQuery in project spring-data-elasticsearch by spring-projects.
the class ElasticsearchTemplateCallbackTests method bulkIndexShouldInvokeAfterSaveCallbacks.
// DATAES-771
@Test
void bulkIndexShouldInvokeAfterSaveCallbacks() {
template.setEntityCallbacks(EntityCallbacks.create(afterSaveCallback));
Person entity1 = new Person("init1", "luke1");
Person entity2 = new Person("init2", "luke2");
IndexQuery query1 = indexQueryForEntity(entity1);
IndexQuery query2 = indexQueryForEntity(entity2);
template.bulkIndex(Arrays.asList(query1, query2), index);
verify(afterSaveCallback, times(2)).onAfterSave(any(), eq(index));
Person savedPerson1 = (Person) query1.getObject();
Person savedPerson2 = (Person) query2.getObject();
assertThat(savedPerson1.firstname).isEqualTo("after-save");
assertThat(savedPerson2.firstname).isEqualTo("after-save");
}
use of org.springframework.data.elasticsearch.core.query.IndexQuery in project spring-data-elasticsearch by spring-projects.
the class LogEntityIntegrationTests method before.
@BeforeEach
public void before() throws ParseException {
indexOperations = operations.indexOps(LogEntity.class);
IndexInitializer.init(indexOperations);
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
IndexQuery indexQuery1 = new LogEntityBuilder("1").action("update").date(dateFormatter.parse("2013-10-18 18:01")).code(2).ip("10.10.10.1").buildIndex();
IndexQuery indexQuery2 = new LogEntityBuilder("2").action("update").date(dateFormatter.parse("2013-10-19 18:02")).code(2).ip("10.10.10.2").buildIndex();
IndexQuery indexQuery3 = new LogEntityBuilder("3").action("update").date(dateFormatter.parse("2013-10-19 18:03")).code(2).ip("10.10.10.3").buildIndex();
IndexQuery indexQuery4 = new LogEntityBuilder("4").action("update").date(dateFormatter.parse("2013-10-19 18:04")).code(2).ip("10.10.10.4").buildIndex();
operations.bulkIndex(Arrays.asList(indexQuery1, indexQuery2, indexQuery3, indexQuery4), index);
indexOperations.refresh();
}
use of org.springframework.data.elasticsearch.core.query.IndexQuery in project spring-data-elasticsearch by spring-projects.
the class CompletionIntegrationTests method loadCompletionObjectEntities.
private void loadCompletionObjectEntities() {
List<IndexQuery> indexQueries = new ArrayList<>();
indexQueries.add(new CompletionEntityBuilder("1").name("Rizwan Idrees").suggest(new String[] { "Rizwan Idrees" }).buildIndex());
indexQueries.add(new CompletionEntityBuilder("2").name("Franck Marchand").suggest(new String[] { "Franck", "Marchand" }).buildIndex());
indexQueries.add(new CompletionEntityBuilder("3").name("Mohsin Husen").suggest(new String[] { "Mohsin", "Husen" }).buildIndex());
indexQueries.add(new CompletionEntityBuilder("4").name("Artur Konczak").suggest(new String[] { "Artur", "Konczak" }).buildIndex());
IndexCoordinates index = IndexCoordinates.of("test-index-core-completion");
operations.bulkIndex(indexQueries, index);
operations.indexOps(CompletionEntity.class).refresh();
}
use of org.springframework.data.elasticsearch.core.query.IndexQuery in project spring-data-elasticsearch by spring-projects.
the class IndexBuilder method buildIndex.
public static IndexQuery buildIndex(Object object) {
for (Field f : object.getClass().getDeclaredFields()) {
if (AnnotationUtils.findAnnotation(f, Id.class) != null) {
try {
f.setAccessible(true);
IndexQuery indexQuery = new IndexQuery();
indexQuery.setId((String) f.get(object));
indexQuery.setObject(object);
return indexQuery;
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
throw new RuntimeException("Missing @Id field");
}
Aggregations