use of org.springframework.data.elasticsearch.core.mapping.IndexCoordinates in project spring-data-elasticsearch by spring-projects.
the class CompletionIntegrationTests method shouldRetrieveEntityWithCompletion.
// DATAES-754
@Test
void shouldRetrieveEntityWithCompletion() {
loadCompletionObjectEntities();
IndexCoordinates index = IndexCoordinates.of("test-index-core-completion");
operations.get("1", CompletionEntity.class, index);
}
use of org.springframework.data.elasticsearch.core.mapping.IndexCoordinates 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.mapping.IndexCoordinates in project spring-data-elasticsearch by spring-projects.
the class DynamicSettingAndMappingEntityRepositoryIntegrationTests method shouldSearchOnGivenTokenizerUsingGivenDynamicSettingsForGivenIndex.
// DATAES-64
@Test
public void shouldSearchOnGivenTokenizerUsingGivenDynamicSettingsForGivenIndex() {
DynamicSettingAndMappingEntity dynamicSettingAndMappingEntity1 = new DynamicSettingAndMappingEntity();
dynamicSettingAndMappingEntity1.setId(nextIdAsString());
dynamicSettingAndMappingEntity1.setName("test-setting1");
dynamicSettingAndMappingEntity1.setEmail("test_setting1@Test.com");
repository.save(dynamicSettingAndMappingEntity1);
DynamicSettingAndMappingEntity dynamicSettingAndMappingEntity2 = new DynamicSettingAndMappingEntity();
dynamicSettingAndMappingEntity2.setId(nextIdAsString());
dynamicSettingAndMappingEntity2.setName("test-setting2");
dynamicSettingAndMappingEntity2.setEmail("test_setting2@Test.com");
repository.save(dynamicSettingAndMappingEntity2);
// use a term query to prevent the input from being analysed
Query searchQuery = new StringQuery("{\"term\": {\"email\": \"" + dynamicSettingAndMappingEntity1.getEmail() + "\"}}\n");
IndexCoordinates index = IndexCoordinates.of(indexNameProvider.indexName());
SearchHits<DynamicSettingAndMappingEntity> entityList = operations.search(searchQuery, DynamicSettingAndMappingEntity.class, index);
assertThat(entityList).hasSize(1);
assertThat(entityList).isNotNull().hasSize(1);
assertThat(entityList.getSearchHit(0).getContent().getEmail()).isEqualTo(dynamicSettingAndMappingEntity1.getEmail());
}
use of org.springframework.data.elasticsearch.core.mapping.IndexCoordinates in project spring-data-elasticsearch by spring-projects.
the class MappingBuilderIntegrationTests method shouldAddStockPriceDocumentToIndex.
// DATAES-530
@Test
public void shouldAddStockPriceDocumentToIndex() {
// Given
IndexOperations indexOps = operations.indexOps(StockPrice.class);
// When
indexOps.create();
indexOps.putMapping(StockPrice.class);
String symbol = "AU";
double price = 2.34;
String id = "abc";
IndexCoordinates index = IndexCoordinates.of("test-index-stock-mapping-builder");
//
StockPrice stockPrice = new StockPrice();
stockPrice.setId(id);
stockPrice.setSymbol(symbol);
stockPrice.setPrice(BigDecimal.valueOf(price));
operations.index(buildIndex(stockPrice), index);
operations.indexOps(StockPrice.class).refresh();
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).build();
SearchHits<StockPrice> result = operations.search(searchQuery, StockPrice.class, index);
// Then
assertThat(result).hasSize(1);
StockPrice entry = result.getSearchHit(0).getContent();
assertThat(entry.getSymbol()).isEqualTo(symbol);
assertThat(entry.getPrice()).isCloseTo(BigDecimal.valueOf(price), Percentage.withPercentage(0.01));
}
use of org.springframework.data.elasticsearch.core.mapping.IndexCoordinates in project spring-data-elasticsearch by spring-projects.
the class ElasticsearchPartQuery method countOrGetDocumentsForDelete.
@Nullable
private Object countOrGetDocumentsForDelete(CriteriaQuery query, ParametersParameterAccessor accessor) {
Object result = null;
Class<?> clazz = queryMethod.getEntityInformation().getJavaType();
IndexCoordinates index = elasticsearchOperations.getIndexCoordinatesFor(clazz);
if (queryMethod.isCollectionQuery()) {
if (accessor.getPageable().isUnpaged()) {
int itemCount = (int) elasticsearchOperations.count(query, clazz, index);
query.setPageable(PageRequest.of(0, Math.max(1, itemCount)));
} else {
query.setPageable(accessor.getPageable());
}
result = elasticsearchOperations.search(query, clazz, index);
}
if (ClassUtils.isAssignable(Number.class, queryMethod.getReturnedObjectType())) {
result = elasticsearchOperations.count(query, clazz, index);
}
return result;
}
Aggregations