mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-12 07:02:10 +00:00
DATAES-130 Added support for Spel Expressions in Type
- Added support for Spel Expressions in index type - Renamed SpELEntityTest to SpELEntityTests so they run when called from maven
This commit is contained in:
parent
1255dfa89d
commit
37802761ed
@ -95,7 +95,8 @@ public class SimpleElasticsearchPersistentEntity<T> extends BasicPersistentEntit
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIndexType() {
|
public String getIndexType() {
|
||||||
return indexType;
|
Expression expression = parser.parseExpression(indexType, ParserContext.TEMPLATE_EXPRESSION);
|
||||||
|
return expression.getValue(context, String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,19 +34,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||||||
* SpELEntityTest
|
* SpELEntityTest
|
||||||
*
|
*
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration("classpath:/spel-repository-test.xml")
|
@ContextConfiguration("classpath:/spel-repository-test.xml")
|
||||||
public class SpELEntityTest {
|
public class SpELEntityTests {
|
||||||
|
|
||||||
|
@Autowired private SpELRepository repository;
|
||||||
|
|
||||||
@Autowired
|
@Autowired private ElasticsearchTemplate template;
|
||||||
private SpELRepository repository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ElasticsearchTemplate template;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() {
|
public void init() {
|
||||||
@ -55,15 +51,31 @@ public class SpELEntityTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldDo() {
|
public void shouldDo() {
|
||||||
//Given
|
// Given
|
||||||
repository.save(new SpELEntity());
|
repository.save(new SpELEntity());
|
||||||
repository.save(new SpELEntity());
|
repository.save(new SpELEntity());
|
||||||
//When
|
// When
|
||||||
|
|
||||||
//Then
|
// Then
|
||||||
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery());
|
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery());
|
||||||
nativeSearchQuery.addIndices("abz-entity");
|
nativeSearchQuery.addIndices("abz-entity");
|
||||||
long count = template.count(nativeSearchQuery);
|
long count = template.count(nativeSearchQuery);
|
||||||
assertThat(count, is(2L));
|
assertThat(count, is(2L));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldSupportSpelInType() {
|
||||||
|
// Given
|
||||||
|
SpELEntity spELEntity = new SpELEntity();
|
||||||
|
repository.save(spELEntity);
|
||||||
|
|
||||||
|
// When
|
||||||
|
|
||||||
|
// Then
|
||||||
|
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery());
|
||||||
|
nativeSearchQuery.addIndices("abz-entity");
|
||||||
|
nativeSearchQuery.addTypes("myType");
|
||||||
|
long count = template.count(nativeSearchQuery);
|
||||||
|
assertThat(count, is(1L));
|
||||||
|
}
|
||||||
}
|
}
|
@ -22,13 +22,12 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
|||||||
* SpELEntity
|
* SpELEntity
|
||||||
*
|
*
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Document(indexName = "#{'abz'+'-'+'entity'}", type = "spel", indexStoreType = "memory", shards = 1, replicas = 0, refreshInterval = "-1")
|
@Document(indexName = "#{'abz'+'-'+'entity'}", type = "#{'my'+'Type'}", indexStoreType = "memory", shards = 1,
|
||||||
|
replicas = 0, refreshInterval = "-1")
|
||||||
public class SpELEntity {
|
public class SpELEntity {
|
||||||
|
|
||||||
@Id
|
@Id private String id;
|
||||||
private String id;
|
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user