mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-22 20:12:11 +00:00
parent
03fd603909
commit
c3714dd6e5
1
pom.xml
1
pom.xml
@ -289,7 +289,6 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -13,8 +13,10 @@ import org.elasticsearch.action.bulk.BulkResponse;
|
|||||||
import org.elasticsearch.action.search.MultiSearchRequest;
|
import org.elasticsearch.action.search.MultiSearchRequest;
|
||||||
import org.elasticsearch.action.search.MultiSearchResponse;
|
import org.elasticsearch.action.search.MultiSearchResponse;
|
||||||
import org.elasticsearch.action.search.SearchRequest;
|
import org.elasticsearch.action.search.SearchRequest;
|
||||||
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.common.collect.MapBuilder;
|
import org.elasticsearch.common.collect.MapBuilder;
|
||||||
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder;
|
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder;
|
||||||
|
import org.elasticsearch.search.suggest.SuggestBuilder;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
@ -259,6 +261,8 @@ public abstract class AbstractElasticsearchTemplate implements ElasticsearchOper
|
|||||||
|
|
||||||
abstract protected MultiSearchResponse.Item[] getMultiSearchResult(MultiSearchRequest request);
|
abstract protected MultiSearchResponse.Item[] getMultiSearchResult(MultiSearchRequest request);
|
||||||
|
|
||||||
|
public abstract SearchResponse suggest(SuggestBuilder suggestion, IndexCoordinates index);
|
||||||
|
|
||||||
protected void setPersistentEntityId(Object entity, String id) {
|
protected void setPersistentEntityId(Object entity, String id) {
|
||||||
|
|
||||||
ElasticsearchPersistentEntity<?> persistentEntity = getPersistentEntityFor(entity.getClass());
|
ElasticsearchPersistentEntity<?> persistentEntity = getPersistentEntityFor(entity.getClass());
|
||||||
|
@ -44,7 +44,7 @@ import org.springframework.data.elasticsearch.annotations.Field;
|
|||||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||||
import org.springframework.data.elasticsearch.annotations.InnerField;
|
import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.query.GetQuery;
|
import org.springframework.data.elasticsearch.core.query.GetQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||||
@ -66,7 +66,7 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
|
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
|
||||||
public class NestedObjectTests {
|
public class NestedObjectTests {
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Autowired private ElasticsearchOperations elasticsearchTemplate;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
@ -123,7 +123,7 @@ public class NestedObjectTests {
|
|||||||
indexQueries.add(indexQuery1);
|
indexQueries.add(indexQuery1);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
IndexCoordinates index = IndexCoordinates.of("test-index-person").withTypes( "user");
|
IndexCoordinates index = IndexCoordinates.of("test-index-person").withTypes("user");
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(Person.class);
|
elasticsearchTemplate.refresh(Person.class);
|
||||||
|
|
||||||
@ -144,14 +144,14 @@ public class NestedObjectTests {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries,
|
elasticsearchTemplate.bulkIndex(indexQueries,
|
||||||
IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes( "user"));
|
IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes("user"));
|
||||||
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
GetQuery getQuery = new GetQuery();
|
GetQuery getQuery = new GetQuery();
|
||||||
getQuery.setId("1");
|
getQuery.setId("1");
|
||||||
PersonMultipleLevelNested personIndexed = elasticsearchTemplate.get(getQuery, PersonMultipleLevelNested.class,
|
PersonMultipleLevelNested personIndexed = elasticsearchTemplate.get(getQuery, PersonMultipleLevelNested.class,
|
||||||
IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes( "user"));
|
IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes("user"));
|
||||||
assertThat(personIndexed).isNotNull();
|
assertThat(personIndexed).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ public class NestedObjectTests {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries,
|
elasticsearchTemplate.bulkIndex(indexQueries,
|
||||||
IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes( "user"));
|
IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes("user"));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
Map<String, Object> mapping = elasticsearchTemplate.getMapping(PersonMultipleLevelNested.class);
|
Map<String, Object> mapping = elasticsearchTemplate.getMapping(PersonMultipleLevelNested.class);
|
||||||
@ -182,9 +182,8 @@ public class NestedObjectTests {
|
|||||||
List<IndexQuery> indexQueries = createPerson();
|
List<IndexQuery> indexQueries = createPerson();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
IndexCoordinates index = IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes( "user");
|
IndexCoordinates index = IndexCoordinates.of("test-index-person-multiple-level-nested").withTypes("user");
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries,
|
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
||||||
index);
|
|
||||||
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -323,7 +322,7 @@ public class NestedObjectTests {
|
|||||||
indexQueries.add(indexQuery1);
|
indexQueries.add(indexQuery1);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
IndexCoordinates index = IndexCoordinates.of("test-index-person").withTypes( "user");
|
IndexCoordinates index = IndexCoordinates.of("test-index-person").withTypes("user");
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(Person.class);
|
elasticsearchTemplate.refresh(Person.class);
|
||||||
|
|
||||||
@ -372,7 +371,7 @@ public class NestedObjectTests {
|
|||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
IndexCoordinates index = IndexCoordinates.of("test-index-book-nested-objects").withTypes( "book");
|
IndexCoordinates index = IndexCoordinates.of("test-index-book-nested-objects").withTypes("book");
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(Book.class);
|
elasticsearchTemplate.refresh(Book.class);
|
||||||
|
|
||||||
|
@ -17,8 +17,8 @@ package org.springframework.data.elasticsearch.config.namespace;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
@ -27,7 +27,7 @@ import org.springframework.data.elasticsearch.client.RestClientFactoryBean;
|
|||||||
import org.springframework.data.elasticsearch.client.TransportClientFactoryBean;
|
import org.springframework.data.elasticsearch.client.TransportClientFactoryBean;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
@ -36,7 +36,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration("namespace.xml")
|
@ContextConfiguration("namespace.xml")
|
||||||
public class ElasticsearchNamespaceHandlerTests {
|
public class ElasticsearchNamespaceHandlerTests {
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ import org.springframework.data.elasticsearch.annotations.Field;
|
|||||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||||
import org.springframework.data.elasticsearch.annotations.Score;
|
import org.springframework.data.elasticsearch.annotations.Score;
|
||||||
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
@ -70,10 +70,10 @@ public class EnableElasticsearchRepositoriesTests implements ApplicationContextA
|
|||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({ ElasticsearchTemplateConfiguration.class })
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
@EnableElasticsearchRepositories(basePackages = { "org.springframework.data.elasticsearch.config.notnested" })
|
@EnableElasticsearchRepositories
|
||||||
static class Config {}
|
static class Config {}
|
||||||
|
|
||||||
@Autowired ElasticsearchTemplate elasticsearchTemplate;
|
@Autowired ElasticsearchOperations operations;
|
||||||
|
|
||||||
@Autowired private SampleElasticsearchRepository repository;
|
@Autowired private SampleElasticsearchRepository repository;
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ public class EnableElasticsearchRepositoriesTests implements ApplicationContextA
|
|||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
IndexInitializer.init(elasticsearchTemplate, SampleEntity.class);
|
IndexInitializer.init(operations, SampleEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1,250 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2014-2019 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.springframework.data.elasticsearch.core;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.*;
|
|
||||||
import static org.elasticsearch.join.query.JoinQueryBuilders.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.lucene.search.join.ScoreMode;
|
|
||||||
import org.elasticsearch.action.RoutingMissingException;
|
|
||||||
import org.elasticsearch.action.update.UpdateRequest;
|
|
||||||
import org.elasticsearch.action.update.UpdateResponse;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
|
||||||
import org.elasticsearch.index.query.QueryBuilders;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.core.style.ToStringCreator;
|
|
||||||
import org.springframework.data.annotation.Id;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
|
||||||
import org.springframework.data.elasticsearch.annotations.Parent;
|
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplateParentChildTests.ParentEntity.ChildEntity;
|
|
||||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
|
||||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
|
||||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Philipp Jardas
|
|
||||||
* @author Peter-Josef Meisch
|
|
||||||
*/
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
|
||||||
public class ElasticsearchTemplateParentChildTests {
|
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void before() {
|
|
||||||
|
|
||||||
IndexInitializer.init(elasticsearchTemplate, ParentEntity.class);
|
|
||||||
IndexInitializer.init(elasticsearchTemplate, ChildEntity.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore(value = "DATAES-421")
|
|
||||||
@Test
|
|
||||||
public void shouldIndexParentChildEntity() {
|
|
||||||
|
|
||||||
// index two parents
|
|
||||||
ParentEntity parent1 = index("parent1", "First Parent");
|
|
||||||
ParentEntity parent2 = index("parent2", "Second Parent");
|
|
||||||
|
|
||||||
// index a child for each parent
|
|
||||||
String child1name = "First";
|
|
||||||
index("child1", parent1.getId(), child1name);
|
|
||||||
index("child2", parent2.getId(), "Second");
|
|
||||||
|
|
||||||
elasticsearchTemplate.refresh(ParentEntity.class);
|
|
||||||
elasticsearchTemplate.refresh(ChildEntity.class);
|
|
||||||
|
|
||||||
// find all parents that have the first child
|
|
||||||
QueryBuilder query = hasChildQuery(ParentEntity.CHILD_TYPE,
|
|
||||||
QueryBuilders.termQuery("name", child1name.toLowerCase()), ScoreMode.None);
|
|
||||||
List<ParentEntity> parents = elasticsearchTemplate.queryForList(new NativeSearchQuery(query), ParentEntity.class, IndexCoordinates.of(ParentEntity.INDEX));
|
|
||||||
|
|
||||||
// we're expecting only the first parent as result
|
|
||||||
assertThat(parents).hasSize(1);
|
|
||||||
assertThat(parents.get(0).getId()).isEqualTo(parent1.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore(value = "DATAES-421")
|
|
||||||
@Test
|
|
||||||
public void shouldUpdateChild() throws Exception {
|
|
||||||
|
|
||||||
// index parent and child
|
|
||||||
ParentEntity parent = index("parent", "Parent");
|
|
||||||
ChildEntity child = index("child", parent.getId(), "Child");
|
|
||||||
String newChildName = "New Child Name";
|
|
||||||
|
|
||||||
// update the child, not forgetting to set the parent id as routing parameter
|
|
||||||
UpdateRequest updateRequest = new UpdateRequest(ParentEntity.INDEX, ParentEntity.CHILD_TYPE, child.getId());
|
|
||||||
updateRequest.routing(parent.getId());
|
|
||||||
XContentBuilder builder;
|
|
||||||
builder = jsonBuilder().startObject().field("name", newChildName).endObject();
|
|
||||||
updateRequest.doc(builder);
|
|
||||||
UpdateResponse response = update(updateRequest, IndexCoordinates.of(ParentEntity.INDEX).withTypes( ParentEntity.CHILD_TYPE));
|
|
||||||
|
|
||||||
assertThat(response.getShardInfo().getSuccessful()).isEqualTo(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore(value = "DATAES-421")
|
|
||||||
@Test(expected = RoutingMissingException.class)
|
|
||||||
public void shouldFailWithRoutingMissingExceptionOnUpdateChildIfNotRoutingSetOnUpdateRequest() throws Exception {
|
|
||||||
|
|
||||||
// index parent and child
|
|
||||||
ParentEntity parent = index("parent", "Parent");
|
|
||||||
ChildEntity child = index("child", parent.getId(), "Child");
|
|
||||||
String newChildName = "New Child Name";
|
|
||||||
|
|
||||||
// update the child, forget routing parameter
|
|
||||||
UpdateRequest updateRequest = new UpdateRequest(ParentEntity.INDEX, ParentEntity.CHILD_TYPE, child.getId());
|
|
||||||
XContentBuilder builder;
|
|
||||||
builder = jsonBuilder().startObject().field("name", newChildName).endObject();
|
|
||||||
updateRequest.doc(builder);
|
|
||||||
update(updateRequest, IndexCoordinates.of(ParentEntity.INDEX).withTypes( ParentEntity.CHILD_TYPE));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Ignore(value = "DATAES-421")
|
|
||||||
@Test(expected = RoutingMissingException.class)
|
|
||||||
public void shouldFailWithRoutingMissingExceptionOnUpdateChildIfRoutingOnlySetOnRequestDoc() throws Exception {
|
|
||||||
|
|
||||||
// index parent and child
|
|
||||||
ParentEntity parent = index("parent", "Parent");
|
|
||||||
ChildEntity child = index("child", parent.getId(), "Child");
|
|
||||||
String newChildName = "New Child Name";
|
|
||||||
|
|
||||||
// update the child
|
|
||||||
UpdateRequest updateRequest = new UpdateRequest(ParentEntity.INDEX, ParentEntity.CHILD_TYPE, child.getId());
|
|
||||||
XContentBuilder builder;
|
|
||||||
builder = jsonBuilder().startObject().field("name", newChildName).endObject();
|
|
||||||
updateRequest.doc(builder);
|
|
||||||
updateRequest.doc().routing(parent.getId());
|
|
||||||
update(updateRequest, IndexCoordinates.of(ParentEntity.INDEX).withTypes( ParentEntity.CHILD_TYPE));
|
|
||||||
}
|
|
||||||
|
|
||||||
private ParentEntity index(String parentId, String name) {
|
|
||||||
|
|
||||||
ParentEntity parent = new ParentEntity(parentId, name);
|
|
||||||
IndexQuery index = new IndexQuery();
|
|
||||||
index.setId(parent.getId());
|
|
||||||
index.setObject(parent);
|
|
||||||
elasticsearchTemplate.index(index, IndexCoordinates.of(ParentEntity.INDEX).withTypes( ParentEntity.PARENT_TYPE));
|
|
||||||
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ChildEntity index(String childId, String parentId, String name) {
|
|
||||||
|
|
||||||
ChildEntity child = new ChildEntity(childId, parentId, name);
|
|
||||||
IndexQuery index = new IndexQuery();
|
|
||||||
index.setId(child.getId());
|
|
||||||
index.setObject(child);
|
|
||||||
index.setParentId(child.getParentId());
|
|
||||||
elasticsearchTemplate.index(index, IndexCoordinates.of(ParentEntity.INDEX).withTypes( ParentEntity.CHILD_TYPE));
|
|
||||||
|
|
||||||
return child;
|
|
||||||
}
|
|
||||||
|
|
||||||
private UpdateResponse update(UpdateRequest updateRequest, IndexCoordinates index) {
|
|
||||||
|
|
||||||
UpdateQuery update = new UpdateQuery();
|
|
||||||
update.setId(updateRequest.id());
|
|
||||||
update.setUpdateRequest(updateRequest);
|
|
||||||
return elasticsearchTemplate.update(update, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Philipp Jardas
|
|
||||||
* @author Mohsin Husen
|
|
||||||
*/
|
|
||||||
@Document(
|
|
||||||
indexName = org.springframework.data.elasticsearch.core.ElasticsearchTemplateParentChildTests.ParentEntity.INDEX,
|
|
||||||
type = org.springframework.data.elasticsearch.core.ElasticsearchTemplateParentChildTests.ParentEntity.PARENT_TYPE,
|
|
||||||
shards = 1, replicas = 0, refreshInterval = "-1")
|
|
||||||
static class ParentEntity {
|
|
||||||
|
|
||||||
public static final String INDEX = "parent-child";
|
|
||||||
public static final String PARENT_TYPE = "parent-entity";
|
|
||||||
public static final String CHILD_TYPE = "child-entity";
|
|
||||||
|
|
||||||
@Id private String id;
|
|
||||||
@Field(type = FieldType.Text, store = true) private String name;
|
|
||||||
|
|
||||||
public ParentEntity() {}
|
|
||||||
|
|
||||||
public ParentEntity(String id, String name) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return new ToStringCreator(this).append("id", id).append("name", name).toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Document(indexName = INDEX, type = CHILD_TYPE, shards = 1, replicas = 0, refreshInterval = "-1")
|
|
||||||
static class ChildEntity {
|
|
||||||
|
|
||||||
@Id private String id;
|
|
||||||
@Field(type = FieldType.Text, store = true) @Parent(type = PARENT_TYPE) private String parentId;
|
|
||||||
@Field(type = FieldType.Text, store = true) private String name;
|
|
||||||
|
|
||||||
public ChildEntity() {}
|
|
||||||
|
|
||||||
public ChildEntity(String id, String parentId, String name) {
|
|
||||||
this.id = id;
|
|
||||||
this.parentId = parentId;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getParentId() {
|
|
||||||
return parentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return new ToStringCreator(this).append("id", id).append("parentId", parentId).append("name", name).toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -27,17 +27,19 @@ import java.util.Arrays;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
@ -50,16 +52,20 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
@SpringIntegrationTest
|
@SpringIntegrationTest
|
||||||
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
|
@ContextConfiguration(classes = { LogEntityTests.Config.class })
|
||||||
public class LogEntityTests {
|
public class LogEntityTests {
|
||||||
|
|
||||||
private final IndexCoordinates index = IndexCoordinates.of("test-index-log-core").withTypes( "test-log-type");
|
@Configuration
|
||||||
@Autowired private ElasticsearchTemplate template;
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
|
static class Config {}
|
||||||
|
|
||||||
|
private final IndexCoordinates index = IndexCoordinates.of("test-index-log-core").withTypes("test-log-type");
|
||||||
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() throws ParseException {
|
public void before() throws ParseException {
|
||||||
|
|
||||||
IndexInitializer.init(template, LogEntity.class);
|
IndexInitializer.init(operations, LogEntity.class);
|
||||||
|
|
||||||
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||||
IndexQuery indexQuery1 = new LogEntityBuilder("1").action("update").date(dateFormatter.parse("2013-10-18 18:01"))
|
IndexQuery indexQuery1 = new LogEntityBuilder("1").action("update").date(dateFormatter.parse("2013-10-18 18:01"))
|
||||||
@ -74,8 +80,8 @@ public class LogEntityTests {
|
|||||||
IndexQuery indexQuery4 = new LogEntityBuilder("4").action("update").date(dateFormatter.parse("2013-10-19 18:04"))
|
IndexQuery indexQuery4 = new LogEntityBuilder("4").action("update").date(dateFormatter.parse("2013-10-19 18:04"))
|
||||||
.code(2).ip("10.10.10.4").buildIndex();
|
.code(2).ip("10.10.10.4").buildIndex();
|
||||||
|
|
||||||
template.bulkIndex(Arrays.asList(indexQuery1, indexQuery2, indexQuery3, indexQuery4), index);
|
operations.bulkIndex(Arrays.asList(indexQuery1, indexQuery2, indexQuery3, indexQuery4), index);
|
||||||
template.refresh(LogEntity.class);
|
operations.refresh(LogEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-66
|
@Test // DATAES-66
|
||||||
@ -83,7 +89,7 @@ public class LogEntityTests {
|
|||||||
|
|
||||||
// when
|
// when
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("ip", "10.10.10.1")).build();
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("ip", "10.10.10.1")).build();
|
||||||
List<LogEntity> entities = template.queryForList(searchQuery, LogEntity.class, index);
|
List<LogEntity> entities = operations.queryForList(searchQuery, LogEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(entities).isNotNull().hasSize(1);
|
assertThat(entities).isNotNull().hasSize(1);
|
||||||
@ -96,8 +102,8 @@ public class LogEntityTests {
|
|||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("ip", "10.10.10")).build();
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("ip", "10.10.10")).build();
|
||||||
|
|
||||||
assertThatThrownBy(() -> {
|
assertThatThrownBy(() -> {
|
||||||
List<LogEntity> entities = template.queryForList(searchQuery, LogEntity.class, index);
|
List<LogEntity> entities = operations.queryForList(searchQuery, LogEntity.class, index);
|
||||||
}).isInstanceOf(SearchPhaseExecutionException.class);
|
}).isInstanceOf(ElasticsearchException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-66
|
@Test // DATAES-66
|
||||||
@ -106,7 +112,7 @@ public class LogEntityTests {
|
|||||||
// when
|
// when
|
||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||||
.withQuery(rangeQuery("ip").from("10.10.10.1").to("10.10.10.3")).build();
|
.withQuery(rangeQuery("ip").from("10.10.10.1").to("10.10.10.3")).build();
|
||||||
List<LogEntity> entities = template.queryForList(searchQuery, LogEntity.class, index);
|
List<LogEntity> entities = operations.queryForList(searchQuery, LogEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(entities).isNotNull().hasSize(3);
|
assertThat(entities).isNotNull().hasSize(3);
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.core;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { LogEntityTransportTests.Config.class })
|
||||||
|
public class LogEntityTransportTests extends LogEntityTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -34,18 +34,20 @@ import org.junit.jupiter.api.AfterEach;
|
|||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.springframework.data.elasticsearch.annotations.InnerField;
|
import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.ResultsExtractor;
|
import org.springframework.data.elasticsearch.core.ResultsExtractor;
|
||||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
@ -58,9 +60,13 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
@SpringIntegrationTest
|
@SpringIntegrationTest
|
||||||
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
|
@ContextConfiguration(classes = { ElasticsearchTemplateAggregationTests.Config.class })
|
||||||
public class ElasticsearchTemplateAggregationTests {
|
public class ElasticsearchTemplateAggregationTests {
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
|
static class Config {}
|
||||||
|
|
||||||
static final String RIZWAN_IDREES = "Rizwan Idrees";
|
static final String RIZWAN_IDREES = "Rizwan Idrees";
|
||||||
static final String MOHSIN_HUSEN = "Mohsin Husen";
|
static final String MOHSIN_HUSEN = "Mohsin Husen";
|
||||||
static final String JONATHAN_YAN = "Jonathan Yan";
|
static final String JONATHAN_YAN = "Jonathan Yan";
|
||||||
@ -70,12 +76,12 @@ public class ElasticsearchTemplateAggregationTests {
|
|||||||
static final int YEAR_2000 = 2000;
|
static final int YEAR_2000 = 2000;
|
||||||
static final String INDEX_NAME = "test-index-articles-core-aggregation";
|
static final String INDEX_NAME = "test-index-articles-core-aggregation";
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
|
|
||||||
IndexInitializer.init(elasticsearchTemplate, ArticleEntity.class);
|
IndexInitializer.init(operations, ArticleEntity.class);
|
||||||
|
|
||||||
IndexQuery article1 = new ArticleEntityBuilder("1").title("article four").subject("computing")
|
IndexQuery article1 = new ArticleEntityBuilder("1").title("article four").subject("computing")
|
||||||
.addAuthor(RIZWAN_IDREES).addAuthor(ARTUR_KONCZAK).addAuthor(MOHSIN_HUSEN).addAuthor(JONATHAN_YAN).score(10)
|
.addAuthor(RIZWAN_IDREES).addAuthor(ARTUR_KONCZAK).addAuthor(MOHSIN_HUSEN).addAuthor(JONATHAN_YAN).score(10)
|
||||||
@ -91,17 +97,17 @@ public class ElasticsearchTemplateAggregationTests {
|
|||||||
.score(40).buildIndex();
|
.score(40).buildIndex();
|
||||||
|
|
||||||
IndexCoordinates index = IndexCoordinates.of(INDEX_NAME).withTypes("article");
|
IndexCoordinates index = IndexCoordinates.of(INDEX_NAME).withTypes("article");
|
||||||
elasticsearchTemplate.index(article1, index);
|
operations.index(article1, index);
|
||||||
elasticsearchTemplate.index(article2, index);
|
operations.index(article2, index);
|
||||||
elasticsearchTemplate.index(article3, index);
|
operations.index(article3, index);
|
||||||
elasticsearchTemplate.index(article4, index);
|
operations.index(article4, index);
|
||||||
elasticsearchTemplate.refresh(ArticleEntity.class);
|
operations.refresh(ArticleEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void after() {
|
public void after() {
|
||||||
|
|
||||||
elasticsearchTemplate.deleteIndex(ArticleEntity.class);
|
operations.deleteIndex(ArticleEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -114,7 +120,7 @@ public class ElasticsearchTemplateAggregationTests {
|
|||||||
.addAggregation(terms("subjects").field("subject")) //
|
.addAggregation(terms("subjects").field("subject")) //
|
||||||
.build();
|
.build();
|
||||||
// when
|
// when
|
||||||
Aggregations aggregations = elasticsearchTemplate.query(searchQuery, new ResultsExtractor<Aggregations>() {
|
Aggregations aggregations = operations.query(searchQuery, new ResultsExtractor<Aggregations>() {
|
||||||
@Override
|
@Override
|
||||||
public Aggregations extract(SearchResponse response) {
|
public Aggregations extract(SearchResponse response) {
|
||||||
return response.getAggregations();
|
return response.getAggregations();
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.core.aggregation;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { ElasticsearchTemplateAggregationTransportTests.Config.class })
|
||||||
|
public class ElasticsearchTemplateAggregationTransportTests extends ElasticsearchTemplateAggregationTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -28,13 +28,16 @@ import org.elasticsearch.search.suggest.SuggestionBuilder;
|
|||||||
import org.elasticsearch.search.suggest.completion.CompletionSuggestion;
|
import org.elasticsearch.search.suggest.completion.CompletionSuggestion;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.CompletionField;
|
import org.springframework.data.elasticsearch.annotations.CompletionField;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate;
|
||||||
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
@ -48,14 +51,18 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
@SpringIntegrationTest
|
@SpringIntegrationTest
|
||||||
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
|
@ContextConfiguration(classes = { ElasticsearchTemplateCompletionTests.Config.class })
|
||||||
public class ElasticsearchTemplateCompletionTests {
|
public class ElasticsearchTemplateCompletionTests {
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Configuration
|
||||||
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
|
static class Config {}
|
||||||
|
|
||||||
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
private void loadCompletionObjectEntities() {
|
private void loadCompletionObjectEntities() {
|
||||||
|
|
||||||
IndexInitializer.init(elasticsearchTemplate, CompletionEntity.class);
|
IndexInitializer.init(operations, CompletionEntity.class);
|
||||||
|
|
||||||
List<IndexQuery> indexQueries = new ArrayList<>();
|
List<IndexQuery> indexQueries = new ArrayList<>();
|
||||||
indexQueries.add(
|
indexQueries.add(
|
||||||
@ -67,13 +74,13 @@ public class ElasticsearchTemplateCompletionTests {
|
|||||||
indexQueries.add(new CompletionEntityBuilder("4").name("Artur Konczak").suggest(new String[] { "Artur", "Konczak" })
|
indexQueries.add(new CompletionEntityBuilder("4").name("Artur Konczak").suggest(new String[] { "Artur", "Konczak" })
|
||||||
.buildIndex());
|
.buildIndex());
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, IndexCoordinates.of("test-index-core-completion").withTypes( "completion-type"));
|
operations.bulkIndex(indexQueries, IndexCoordinates.of("test-index-core-completion").withTypes("completion-type"));
|
||||||
elasticsearchTemplate.refresh(CompletionEntity.class);
|
operations.refresh(CompletionEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadAnnotatedCompletionObjectEntities() {
|
private void loadAnnotatedCompletionObjectEntities() {
|
||||||
|
|
||||||
IndexInitializer.init(elasticsearchTemplate, AnnotatedCompletionEntity.class);
|
IndexInitializer.init(operations, AnnotatedCompletionEntity.class);
|
||||||
|
|
||||||
NonDocumentEntity nonDocumentEntity = new NonDocumentEntity();
|
NonDocumentEntity nonDocumentEntity = new NonDocumentEntity();
|
||||||
nonDocumentEntity.setSomeField1("foo");
|
nonDocumentEntity.setSomeField1("foo");
|
||||||
@ -89,14 +96,14 @@ public class ElasticsearchTemplateCompletionTests {
|
|||||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("4").name("Artur Konczak")
|
indexQueries.add(new AnnotatedCompletionEntityBuilder("4").name("Artur Konczak")
|
||||||
.suggest(new String[] { "Artur", "Konczak" }).buildIndex());
|
.suggest(new String[] { "Artur", "Konczak" }).buildIndex());
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries,
|
operations.bulkIndex(indexQueries,
|
||||||
IndexCoordinates.of("test-index-annotated-completion").withTypes( "annotated-completion-type"));
|
IndexCoordinates.of("test-index-annotated-completion").withTypes("annotated-completion-type"));
|
||||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class);
|
operations.refresh(AnnotatedCompletionEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadAnnotatedCompletionObjectEntitiesWithWeights() {
|
private void loadAnnotatedCompletionObjectEntitiesWithWeights() {
|
||||||
|
|
||||||
IndexInitializer.init(elasticsearchTemplate, AnnotatedCompletionEntity.class);
|
IndexInitializer.init(operations, AnnotatedCompletionEntity.class);
|
||||||
|
|
||||||
List<IndexQuery> indexQueries = new ArrayList<>();
|
List<IndexQuery> indexQueries = new ArrayList<>();
|
||||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("1").name("Mewes Kochheim1")
|
indexQueries.add(new AnnotatedCompletionEntityBuilder("1").name("Mewes Kochheim1")
|
||||||
@ -108,9 +115,9 @@ public class ElasticsearchTemplateCompletionTests {
|
|||||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("4").name("Mewes Kochheim4")
|
indexQueries.add(new AnnotatedCompletionEntityBuilder("4").name("Mewes Kochheim4")
|
||||||
.suggest(new String[] { "Mewes Kochheim4" }, Integer.MAX_VALUE).buildIndex());
|
.suggest(new String[] { "Mewes Kochheim4" }, Integer.MAX_VALUE).buildIndex());
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries,
|
operations.bulkIndex(indexQueries,
|
||||||
IndexCoordinates.of("test-index-annotated-completion").withTypes( "annotated-completion-type"));
|
IndexCoordinates.of("test-index-annotated-completion").withTypes("annotated-completion-type"));
|
||||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class);
|
operations.refresh(AnnotatedCompletionEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -118,10 +125,10 @@ public class ElasticsearchTemplateCompletionTests {
|
|||||||
|
|
||||||
// given
|
// given
|
||||||
Class entity = CompletionEntity.class;
|
Class entity = CompletionEntity.class;
|
||||||
elasticsearchTemplate.createIndex(entity);
|
operations.createIndex(entity);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
assertThat(elasticsearchTemplate.putMapping(entity)).isTrue();
|
assertThat(operations.putMapping(entity)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -134,9 +141,9 @@ public class ElasticsearchTemplateCompletionTests {
|
|||||||
Fuzziness.AUTO);
|
Fuzziness.AUTO);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SearchResponse suggestResponse = elasticsearchTemplate.suggest(
|
SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(
|
||||||
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
|
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
|
||||||
IndexCoordinates.of("test-index-core-completion").withTypes( "completion-type"));
|
IndexCoordinates.of("test-index-core-completion").withTypes("completion-type"));
|
||||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||||
|
|
||||||
@ -155,9 +162,9 @@ public class ElasticsearchTemplateCompletionTests {
|
|||||||
Fuzziness.AUTO);
|
Fuzziness.AUTO);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SearchResponse suggestResponse = elasticsearchTemplate.suggest(
|
SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(
|
||||||
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
|
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
|
||||||
IndexCoordinates.of("test-index-core-completion").withTypes( "completion-type"));
|
IndexCoordinates.of("test-index-core-completion").withTypes("completion-type"));
|
||||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||||
|
|
||||||
@ -176,9 +183,9 @@ public class ElasticsearchTemplateCompletionTests {
|
|||||||
Fuzziness.AUTO);
|
Fuzziness.AUTO);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SearchResponse suggestResponse = elasticsearchTemplate.suggest(
|
SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(
|
||||||
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
|
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
|
||||||
IndexCoordinates.of("test-index-annotated-completion").withTypes( "annotated-completion-type"));
|
IndexCoordinates.of("test-index-annotated-completion").withTypes("annotated-completion-type"));
|
||||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||||
|
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.core.completion;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { ElasticsearchTemplateCompletionTransportTests.Config.class })
|
||||||
|
public class ElasticsearchTemplateCompletionTransportTests extends ElasticsearchTemplateCompletionTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -35,14 +35,17 @@ import org.elasticsearch.search.suggest.completion.context.CategoryQueryContext;
|
|||||||
import org.elasticsearch.search.suggest.completion.context.ContextMapping;
|
import org.elasticsearch.search.suggest.completion.context.ContextMapping;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.CompletionContext;
|
import org.springframework.data.elasticsearch.annotations.CompletionContext;
|
||||||
import org.springframework.data.elasticsearch.annotations.CompletionField;
|
import org.springframework.data.elasticsearch.annotations.CompletionField;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.AbstractElasticsearchTemplate;
|
||||||
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
@ -52,14 +55,18 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
@SpringIntegrationTest
|
@SpringIntegrationTest
|
||||||
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
|
@ContextConfiguration(classes = { ElasticsearchTemplateCompletionWithContextsTests.Config.class })
|
||||||
public class ElasticsearchTemplateCompletionWithContextsTests {
|
public class ElasticsearchTemplateCompletionWithContextsTests {
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Configuration
|
||||||
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
|
static class Config {}
|
||||||
|
|
||||||
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
private void loadContextCompletionObjectEntities() {
|
private void loadContextCompletionObjectEntities() {
|
||||||
|
|
||||||
IndexInitializer.init(elasticsearchTemplate, ContextCompletionEntity.class);
|
IndexInitializer.init(operations, ContextCompletionEntity.class);
|
||||||
|
|
||||||
NonDocumentEntity nonDocumentEntity = new NonDocumentEntity();
|
NonDocumentEntity nonDocumentEntity = new NonDocumentEntity();
|
||||||
nonDocumentEntity.setSomeField1("foo");
|
nonDocumentEntity.setSomeField1("foo");
|
||||||
@ -87,9 +94,9 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
|
|||||||
indexQueries.add(new ContextCompletionEntityBuilder("4").name("Artur Konczak")
|
indexQueries.add(new ContextCompletionEntityBuilder("4").name("Artur Konczak")
|
||||||
.suggest(new String[] { "Artur", "Konczak" }, context4).buildIndex());
|
.suggest(new String[] { "Artur", "Konczak" }, context4).buildIndex());
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries,
|
operations.bulkIndex(indexQueries,
|
||||||
IndexCoordinates.of("test-index-context-completion").withTypes( "context-completion-type"));
|
IndexCoordinates.of("test-index-context-completion").withTypes("context-completion-type"));
|
||||||
elasticsearchTemplate.refresh(ContextCompletionEntity.class);
|
operations.refresh(ContextCompletionEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -97,10 +104,10 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
|
|||||||
|
|
||||||
// given
|
// given
|
||||||
Class<?> entity = ContextCompletionEntity.class;
|
Class<?> entity = ContextCompletionEntity.class;
|
||||||
elasticsearchTemplate.createIndex(entity);
|
operations.createIndex(entity);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
assertThat(elasticsearchTemplate.putMapping(entity)).isTrue();
|
assertThat(operations.putMapping(entity)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-536
|
@Test // DATAES-536
|
||||||
@ -123,9 +130,9 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
|
|||||||
((CompletionSuggestionBuilder) completionSuggestionFuzzyBuilder).contexts(contextMap);
|
((CompletionSuggestionBuilder) completionSuggestionFuzzyBuilder).contexts(contextMap);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SearchResponse suggestResponse = elasticsearchTemplate.suggest(
|
SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(
|
||||||
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
|
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
|
||||||
IndexCoordinates.of("test-index-context-completion").withTypes( "context-completion-type"));
|
IndexCoordinates.of("test-index-context-completion").withTypes("context-completion-type"));
|
||||||
assertThat(suggestResponse.getSuggest()).isNotNull();
|
assertThat(suggestResponse.getSuggest()).isNotNull();
|
||||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||||
@ -155,9 +162,9 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
|
|||||||
((CompletionSuggestionBuilder) completionSuggestionFuzzyBuilder).contexts(contextMap);
|
((CompletionSuggestionBuilder) completionSuggestionFuzzyBuilder).contexts(contextMap);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SearchResponse suggestResponse = elasticsearchTemplate.suggest(
|
SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(
|
||||||
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
|
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
|
||||||
IndexCoordinates.of("test-index-context-completion").withTypes( "context-completion-type"));
|
IndexCoordinates.of("test-index-context-completion").withTypes("context-completion-type"));
|
||||||
assertThat(suggestResponse.getSuggest()).isNotNull();
|
assertThat(suggestResponse.getSuggest()).isNotNull();
|
||||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||||
@ -187,9 +194,9 @@ public class ElasticsearchTemplateCompletionWithContextsTests {
|
|||||||
((CompletionSuggestionBuilder) completionSuggestionFuzzyBuilder).contexts(contextMap);
|
((CompletionSuggestionBuilder) completionSuggestionFuzzyBuilder).contexts(contextMap);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SearchResponse suggestResponse = elasticsearchTemplate.suggest(
|
SearchResponse suggestResponse = ((AbstractElasticsearchTemplate) operations).suggest(
|
||||||
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
|
new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder),
|
||||||
IndexCoordinates.of("test-index-context-completion").withTypes( "context-completion-type"));
|
IndexCoordinates.of("test-index-context-completion").withTypes("context-completion-type"));
|
||||||
assertThat(suggestResponse.getSuggest()).isNotNull();
|
assertThat(suggestResponse.getSuggest()).isNotNull();
|
||||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.core.completion;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { ElasticsearchTemplateCompletionWithContextsTransportTests.Config.class })
|
||||||
|
public class ElasticsearchTemplateCompletionWithContextsTransportTests
|
||||||
|
extends ElasticsearchTemplateCompletionWithContextsTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -32,16 +32,18 @@ import org.elasticsearch.index.query.QueryBuilders;
|
|||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.GeoPointField;
|
import org.springframework.data.elasticsearch.annotations.GeoPointField;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.query.Criteria;
|
import org.springframework.data.elasticsearch.core.query.Criteria;
|
||||||
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
||||||
import org.springframework.data.geo.Point;
|
import org.springframework.data.geo.Point;
|
||||||
@ -59,21 +61,25 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
* Latitude , max Longitude , max Latitude
|
* Latitude , max Longitude , max Latitude
|
||||||
*/
|
*/
|
||||||
@SpringIntegrationTest
|
@SpringIntegrationTest
|
||||||
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
|
@ContextConfiguration(classes = { ElasticsearchTemplateGeoTests.Config.class })
|
||||||
public class ElasticsearchTemplateGeoTests {
|
public class ElasticsearchTemplateGeoTests {
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
|
static class Config {}
|
||||||
|
|
||||||
private final IndexCoordinates locationMarkerIndex = IndexCoordinates.of("test-index-location-marker-core-geo")
|
private final IndexCoordinates locationMarkerIndex = IndexCoordinates.of("test-index-location-marker-core-geo")
|
||||||
.withTypes("geo-annotation-point-type");
|
.withTypes("geo-annotation-point-type");
|
||||||
private final IndexCoordinates authorMarkerIndex = IndexCoordinates.of("test-index-author-marker-core-geo")
|
private final IndexCoordinates authorMarkerIndex = IndexCoordinates.of("test-index-author-marker-core-geo")
|
||||||
.withTypes("geo-class-point-type");
|
.withTypes("geo-class-point-type");
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
|
|
||||||
IndexInitializer.init(elasticsearchTemplate, AuthorMarkerEntity.class);
|
IndexInitializer.init(operations, AuthorMarkerEntity.class);
|
||||||
IndexInitializer.init(elasticsearchTemplate, LocationMarkerEntity.class);
|
IndexInitializer.init(operations, LocationMarkerEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadClassBaseEntities() {
|
private void loadClassBaseEntities() {
|
||||||
@ -83,8 +89,8 @@ public class ElasticsearchTemplateGeoTests {
|
|||||||
.add(new AuthorMarkerEntityBuilder("1").name("Franck Marchand").location(45.7806d, 3.0875d).buildIndex());
|
.add(new AuthorMarkerEntityBuilder("1").name("Franck Marchand").location(45.7806d, 3.0875d).buildIndex());
|
||||||
indexQueries.add(new AuthorMarkerEntityBuilder("2").name("Mohsin Husen").location(51.5171d, 0.1062d).buildIndex());
|
indexQueries.add(new AuthorMarkerEntityBuilder("2").name("Mohsin Husen").location(51.5171d, 0.1062d).buildIndex());
|
||||||
indexQueries.add(new AuthorMarkerEntityBuilder("3").name("Rizwan Idrees").location(51.5171d, 0.1062d).buildIndex());
|
indexQueries.add(new AuthorMarkerEntityBuilder("3").name("Rizwan Idrees").location(51.5171d, 0.1062d).buildIndex());
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, authorMarkerIndex);
|
operations.bulkIndex(indexQueries, authorMarkerIndex);
|
||||||
elasticsearchTemplate.refresh(AuthorMarkerEntity.class);
|
operations.refresh(AuthorMarkerEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadAnnotationBaseEntities() {
|
private void loadAnnotationBaseEntities() {
|
||||||
@ -115,8 +121,8 @@ public class ElasticsearchTemplateGeoTests {
|
|||||||
indexQueries.add(buildIndex(location2));
|
indexQueries.add(buildIndex(location2));
|
||||||
indexQueries.add(buildIndex(location3));
|
indexQueries.add(buildIndex(location3));
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, locationMarkerIndex);
|
operations.bulkIndex(indexQueries, locationMarkerIndex);
|
||||||
elasticsearchTemplate.refresh(LocationMarkerEntity.class);
|
operations.refresh(LocationMarkerEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -124,10 +130,10 @@ public class ElasticsearchTemplateGeoTests {
|
|||||||
|
|
||||||
// given
|
// given
|
||||||
Class<?> entity = AuthorMarkerEntity.class;
|
Class<?> entity = AuthorMarkerEntity.class;
|
||||||
elasticsearchTemplate.createIndex(entity);
|
operations.createIndex(entity);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
assertThat(elasticsearchTemplate.putMapping(entity)).isTrue();
|
assertThat(operations.putMapping(entity)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -139,7 +145,7 @@ public class ElasticsearchTemplateGeoTests {
|
|||||||
new Criteria("location").within(new GeoPoint(45.7806d, 3.0875d), "20km"));
|
new Criteria("location").within(new GeoPoint(45.7806d, 3.0875d), "20km"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery,
|
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria = operations.queryForList(geoLocationCriteriaQuery,
|
||||||
AuthorMarkerEntity.class, authorMarkerIndex);
|
AuthorMarkerEntity.class, authorMarkerIndex);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -156,7 +162,7 @@ public class ElasticsearchTemplateGeoTests {
|
|||||||
new Criteria("name").is("Mohsin Husen").and("location").within(new GeoPoint(51.5171d, 0.1062d), "20km"));
|
new Criteria("name").is("Mohsin Husen").and("location").within(new GeoPoint(51.5171d, 0.1062d), "20km"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria2 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery2,
|
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria2 = operations.queryForList(geoLocationCriteriaQuery2,
|
||||||
AuthorMarkerEntity.class, authorMarkerIndex);
|
AuthorMarkerEntity.class, authorMarkerIndex);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -172,7 +178,7 @@ public class ElasticsearchTemplateGeoTests {
|
|||||||
CriteriaQuery geoLocationCriteriaQuery = new CriteriaQuery(
|
CriteriaQuery geoLocationCriteriaQuery = new CriteriaQuery(
|
||||||
new Criteria("locationAsString").within(new GeoPoint(51.000000, 0.100000), "1km"));
|
new Criteria("locationAsString").within(new GeoPoint(51.000000, 0.100000), "1km"));
|
||||||
// when
|
// when
|
||||||
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery,
|
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = operations.queryForList(geoLocationCriteriaQuery,
|
||||||
LocationMarkerEntity.class, locationMarkerIndex);
|
LocationMarkerEntity.class, locationMarkerIndex);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -188,7 +194,7 @@ public class ElasticsearchTemplateGeoTests {
|
|||||||
new Criteria("locationAsArray").within(new GeoPoint(51.001000, 0.10100), "1km"));
|
new Criteria("locationAsArray").within(new GeoPoint(51.001000, 0.10100), "1km"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery,
|
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = operations.queryForList(geoLocationCriteriaQuery,
|
||||||
LocationMarkerEntity.class, locationMarkerIndex);
|
LocationMarkerEntity.class, locationMarkerIndex);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -203,7 +209,7 @@ public class ElasticsearchTemplateGeoTests {
|
|||||||
CriteriaQuery geoLocationCriteriaQuery = new CriteriaQuery(
|
CriteriaQuery geoLocationCriteriaQuery = new CriteriaQuery(
|
||||||
new Criteria("locationAsArray").within("51.001000, 0.10100", "1km"));
|
new Criteria("locationAsArray").within("51.001000, 0.10100", "1km"));
|
||||||
// when
|
// when
|
||||||
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery,
|
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = operations.queryForList(geoLocationCriteriaQuery,
|
||||||
LocationMarkerEntity.class, locationMarkerIndex);
|
LocationMarkerEntity.class, locationMarkerIndex);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -218,7 +224,7 @@ public class ElasticsearchTemplateGeoTests {
|
|||||||
CriteriaQuery geoLocationCriteriaQuery = new CriteriaQuery(new Criteria("locationAsArray").within("u1044", "3km"));
|
CriteriaQuery geoLocationCriteriaQuery = new CriteriaQuery(new Criteria("locationAsArray").within("u1044", "3km"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery,
|
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = operations.queryForList(geoLocationCriteriaQuery,
|
||||||
LocationMarkerEntity.class, locationMarkerIndex);
|
LocationMarkerEntity.class, locationMarkerIndex);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -234,7 +240,7 @@ public class ElasticsearchTemplateGeoTests {
|
|||||||
.withFilter(QueryBuilders.geoBoundingBoxQuery("locationAsArray").setCorners(52, -1, 50, 1));
|
.withFilter(QueryBuilders.geoBoundingBoxQuery("locationAsArray").setCorners(52, -1, 50, 1));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(queryBuilder.build(),
|
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = operations.queryForList(queryBuilder.build(),
|
||||||
LocationMarkerEntity.class, locationMarkerIndex);
|
LocationMarkerEntity.class, locationMarkerIndex);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -250,7 +256,7 @@ public class ElasticsearchTemplateGeoTests {
|
|||||||
new Criteria("location").boundedBy(new GeoBox(new GeoPoint(53.5171d, 0), new GeoPoint(49.5171d, 0.2062d))));
|
new Criteria("location").boundedBy(new GeoBox(new GeoPoint(53.5171d, 0), new GeoPoint(49.5171d, 0.2062d))));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery3,
|
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = operations.queryForList(geoLocationCriteriaQuery3,
|
||||||
AuthorMarkerEntity.class, authorMarkerIndex);
|
AuthorMarkerEntity.class, authorMarkerIndex);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -268,7 +274,7 @@ public class ElasticsearchTemplateGeoTests {
|
|||||||
new Criteria("location").boundedBy(Geohash.stringEncode(0, 53.5171d), Geohash.stringEncode(0.2062d, 49.5171d)));
|
new Criteria("location").boundedBy(Geohash.stringEncode(0, 53.5171d), Geohash.stringEncode(0.2062d, 49.5171d)));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery3,
|
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = operations.queryForList(geoLocationCriteriaQuery3,
|
||||||
AuthorMarkerEntity.class, authorMarkerIndex);
|
AuthorMarkerEntity.class, authorMarkerIndex);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -286,7 +292,7 @@ public class ElasticsearchTemplateGeoTests {
|
|||||||
new Criteria("location").boundedBy(new GeoPoint(53.5171d, 0), new GeoPoint(49.5171d, 0.2062d)));
|
new Criteria("location").boundedBy(new GeoPoint(53.5171d, 0), new GeoPoint(49.5171d, 0.2062d)));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery3,
|
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = operations.queryForList(geoLocationCriteriaQuery3,
|
||||||
AuthorMarkerEntity.class, authorMarkerIndex);
|
AuthorMarkerEntity.class, authorMarkerIndex);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -304,7 +310,7 @@ public class ElasticsearchTemplateGeoTests {
|
|||||||
new Criteria("location").boundedBy(new Point(53.5171d, 0), new Point(49.5171d, 0.2062d)));
|
new Criteria("location").boundedBy(new Point(53.5171d, 0), new Point(49.5171d, 0.2062d)));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery3,
|
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = operations.queryForList(geoLocationCriteriaQuery3,
|
||||||
AuthorMarkerEntity.class, authorMarkerIndex);
|
AuthorMarkerEntity.class, authorMarkerIndex);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -332,18 +338,18 @@ public class ElasticsearchTemplateGeoTests {
|
|||||||
.withFilter(QueryBuilders.geoBoundingBoxQuery("locationAsGeoHash").setCorners("u10j46mkfek"));
|
.withFilter(QueryBuilders.geoBoundingBoxQuery("locationAsGeoHash").setCorners("u10j46mkfek"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
List<LocationMarkerEntity> result1 = elasticsearchTemplate.queryForList(location1.build(),
|
List<LocationMarkerEntity> result1 = operations.queryForList(location1.build(), LocationMarkerEntity.class,
|
||||||
LocationMarkerEntity.class, locationMarkerIndex);
|
locationMarkerIndex);
|
||||||
List<LocationMarkerEntity> result2 = elasticsearchTemplate.queryForList(location2.build(),
|
List<LocationMarkerEntity> result2 = operations.queryForList(location2.build(), LocationMarkerEntity.class,
|
||||||
LocationMarkerEntity.class, locationMarkerIndex);
|
locationMarkerIndex);
|
||||||
List<LocationMarkerEntity> result3 = elasticsearchTemplate.queryForList(location3.build(),
|
List<LocationMarkerEntity> result3 = operations.queryForList(location3.build(), LocationMarkerEntity.class,
|
||||||
LocationMarkerEntity.class, locationMarkerIndex);
|
locationMarkerIndex);
|
||||||
List<LocationMarkerEntity> result4 = elasticsearchTemplate.queryForList(location4.build(),
|
List<LocationMarkerEntity> result4 = operations.queryForList(location4.build(), LocationMarkerEntity.class,
|
||||||
LocationMarkerEntity.class, locationMarkerIndex);
|
locationMarkerIndex);
|
||||||
List<LocationMarkerEntity> result5 = elasticsearchTemplate.queryForList(location5.build(),
|
List<LocationMarkerEntity> result5 = operations.queryForList(location5.build(), LocationMarkerEntity.class,
|
||||||
LocationMarkerEntity.class, locationMarkerIndex);
|
locationMarkerIndex);
|
||||||
List<LocationMarkerEntity> result11 = elasticsearchTemplate.queryForList(location11.build(),
|
List<LocationMarkerEntity> result11 = operations.queryForList(location11.build(), LocationMarkerEntity.class,
|
||||||
LocationMarkerEntity.class, locationMarkerIndex);
|
locationMarkerIndex);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result1).hasSize(3);
|
assertThat(result1).hasSize(3);
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.core.geo;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { ElasticsearchTemplateGeoTransportTests.Config.class })
|
||||||
|
public class ElasticsearchTemplateGeoTransportTests extends ElasticsearchTemplateGeoTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -33,15 +33,17 @@ import java.util.List;
|
|||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.annotation.Version;
|
import org.springframework.data.annotation.Version;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.springframework.data.elasticsearch.annotations.Score;
|
import org.springframework.data.elasticsearch.annotations.Score;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
@ -52,19 +54,24 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
* @author James Bodkin
|
* @author James Bodkin
|
||||||
*/
|
*/
|
||||||
@SpringIntegrationTest
|
@SpringIntegrationTest
|
||||||
@ContextConfiguration(classes = { ElasticsearchTemplateConfiguration.class })
|
@ContextConfiguration(classes = { CriteriaQueryTests.Config.class })
|
||||||
public class CriteriaQueryTests {
|
public class CriteriaQueryTests {
|
||||||
|
|
||||||
private final IndexCoordinates index = IndexCoordinates.of("test-index-sample-core-query").withTypes( "test-type");
|
@Configuration
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
|
static class Config {}
|
||||||
|
|
||||||
|
private final IndexCoordinates index = IndexCoordinates.of("test-index-sample-core-query").withTypes("test-type");
|
||||||
|
|
||||||
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
|
|
||||||
elasticsearchTemplate.deleteIndex(SampleEntity.class);
|
operations.deleteIndex(SampleEntity.class);
|
||||||
elasticsearchTemplate.createIndex(SampleEntity.class);
|
operations.createIndex(SampleEntity.class);
|
||||||
elasticsearchTemplate.putMapping(SampleEntity.class);
|
operations.putMapping(SampleEntity.class);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -80,13 +87,13 @@ public class CriteriaQueryTests {
|
|||||||
IndexQuery indexQuery = new IndexQuery();
|
IndexQuery indexQuery = new IndexQuery();
|
||||||
indexQuery.setId(documentId);
|
indexQuery.setId(documentId);
|
||||||
indexQuery.setObject(sampleEntity);
|
indexQuery.setObject(sampleEntity);
|
||||||
elasticsearchTemplate.index(indexQuery, index);
|
operations.index(indexQuery, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(
|
CriteriaQuery criteriaQuery = new CriteriaQuery(
|
||||||
new Criteria("message").contains("test").and("message").contains("some"));
|
new Criteria("message").contains("test").and("message").contains("some"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SampleEntity sampleEntity1 = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
|
SampleEntity sampleEntity1 = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(sampleEntity1).isNotNull();
|
assertThat(sampleEntity1).isNotNull();
|
||||||
@ -123,13 +130,13 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery2.setObject(sampleEntity2);
|
indexQuery2.setObject(sampleEntity2);
|
||||||
|
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(
|
CriteriaQuery criteriaQuery = new CriteriaQuery(
|
||||||
new Criteria("message").contains("some").or("message").contains("test"));
|
new Criteria("message").contains("some").or("message").contains("test"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(page).isNotNull();
|
assertThat(page).isNotNull();
|
||||||
@ -154,13 +161,13 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery.setObject(sampleEntity);
|
indexQuery.setObject(sampleEntity);
|
||||||
indexQueries.add(indexQuery);
|
indexQueries.add(indexQuery);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria().and(new Criteria("message").contains("some")));
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria().and(new Criteria("message").contains("some")));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
|
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(page).isNotNull();
|
assertThat(page).isNotNull();
|
||||||
@ -186,12 +193,12 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery.setObject(sampleEntity);
|
indexQuery.setObject(sampleEntity);
|
||||||
indexQueries.add(indexQuery);
|
indexQueries.add(indexQuery);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria().or(new Criteria("message").contains("some")));
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria().or(new Criteria("message").contains("some")));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(page).isNotNull();
|
assertThat(page).isNotNull();
|
||||||
@ -215,12 +222,12 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery.setObject(sampleEntity);
|
indexQuery.setObject(sampleEntity);
|
||||||
indexQueries.add(indexQuery);
|
indexQueries.add(indexQuery);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("some message"));
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("some message"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
|
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
|
||||||
@ -257,12 +264,12 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery2.setObject(sampleEntity2);
|
indexQuery2.setObject(sampleEntity2);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("some message"));
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("some message"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
|
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
|
||||||
@ -299,13 +306,13 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery2.setObject(sampleEntity2);
|
indexQuery2.setObject(sampleEntity2);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
Criteria criteria = new Criteria("message").endsWith("end");
|
Criteria criteria = new Criteria("message").endsWith("end");
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(criteria);
|
CriteriaQuery criteriaQuery = new CriteriaQuery(criteria);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SampleEntity sampleEntity = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
|
SampleEntity sampleEntity = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
|
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
|
||||||
@ -341,13 +348,13 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery2.setObject(sampleEntity2);
|
indexQuery2.setObject(sampleEntity2);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
Criteria criteria = new Criteria("message").startsWith("start");
|
Criteria criteria = new Criteria("message").startsWith("start");
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(criteria);
|
CriteriaQuery criteriaQuery = new CriteriaQuery(criteria);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SampleEntity sampleEntity = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
|
SampleEntity sampleEntity = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
|
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
|
||||||
@ -383,12 +390,12 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery2.setObject(sampleEntity2);
|
indexQuery2.setObject(sampleEntity2);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").contains("contains"));
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").contains("contains"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SampleEntity sampleEntity = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
|
SampleEntity sampleEntity = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
|
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
|
||||||
@ -424,12 +431,12 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery2.setObject(sampleEntity2);
|
indexQuery2.setObject(sampleEntity2);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").expression("+elasticsearch || test"));
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").expression("+elasticsearch || test"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SampleEntity sampleEntity = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
|
SampleEntity sampleEntity = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
|
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
|
||||||
@ -465,13 +472,13 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery2.setObject(sampleEntity2);
|
indexQuery2.setObject(sampleEntity2);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(
|
CriteriaQuery criteriaQuery = new CriteriaQuery(
|
||||||
new Criteria("message").startsWith("some").endsWith("search").contains("message").is("some message search"));
|
new Criteria("message").startsWith("some").endsWith("search").contains("message").is("some message search"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SampleEntity sampleEntity = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
|
SampleEntity sampleEntity = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
|
assertThat(criteriaQuery.getCriteria().getField().getName()).isEqualTo("message");
|
||||||
@ -507,12 +514,12 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery2.setObject(sampleEntity2);
|
indexQuery2.setObject(sampleEntity2);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("foo").not());
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("foo").not());
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(criteriaQuery.getCriteria().isNegating()).isTrue();
|
assertThat(criteriaQuery.getCriteria().isNegating()).isTrue();
|
||||||
@ -551,12 +558,12 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery2.setObject(sampleEntity2);
|
indexQuery2.setObject(sampleEntity2);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").between(100, 150));
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").between(100, 150));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SampleEntity sampleEntity = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
|
SampleEntity sampleEntity = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(sampleEntity).isNotNull();
|
assertThat(sampleEntity).isNotNull();
|
||||||
@ -593,12 +600,12 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery2.setObject(sampleEntity2);
|
indexQuery2.setObject(sampleEntity2);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").between(350, null));
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").between(350, null));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(page).isNotNull();
|
assertThat(page).isNotNull();
|
||||||
@ -636,12 +643,12 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery2.setObject(sampleEntity2);
|
indexQuery2.setObject(sampleEntity2);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").between(null, 550));
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").between(null, 550));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(page).isNotNull();
|
assertThat(page).isNotNull();
|
||||||
@ -679,12 +686,12 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery2.setObject(sampleEntity2);
|
indexQuery2.setObject(sampleEntity2);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").lessThanEqual(750));
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").lessThanEqual(750));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(page).isNotNull();
|
assertThat(page).isNotNull();
|
||||||
@ -722,12 +729,12 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery2.setObject(sampleEntity2);
|
indexQuery2.setObject(sampleEntity2);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").greaterThanEqual(950));
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("rate").greaterThanEqual(950));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(page).isNotNull();
|
assertThat(page).isNotNull();
|
||||||
@ -765,12 +772,12 @@ public class CriteriaQueryTests {
|
|||||||
indexQuery2.setObject(sampleEntity2);
|
indexQuery2.setObject(sampleEntity2);
|
||||||
indexQueries.add(indexQuery2);
|
indexQueries.add(indexQuery2);
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").contains("foo").boost(1));
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").contains("foo").boost(1));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(page.getTotalElements()).isGreaterThanOrEqualTo(1);
|
assertThat(page.getTotalElements()).isGreaterThanOrEqualTo(1);
|
||||||
@ -786,14 +793,14 @@ public class CriteriaQueryTests {
|
|||||||
indexQueries.add(buildIndex(SampleEntity.builder().id("2").message("bc").build()));
|
indexQueries.add(buildIndex(SampleEntity.builder().id("2").message("bc").build()));
|
||||||
indexQueries.add(buildIndex(SampleEntity.builder().id("3").message("ac").build()));
|
indexQueries.add(buildIndex(SampleEntity.builder().id("3").message("ac").build()));
|
||||||
|
|
||||||
elasticsearchTemplate.bulkIndex(indexQueries, index);
|
operations.bulkIndex(indexQueries, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(
|
CriteriaQuery criteriaQuery = new CriteriaQuery(
|
||||||
new Criteria("message").contains("a").or(new Criteria("message").contains("b")));
|
new Criteria("message").contains("a").or(new Criteria("message").contains("b")));
|
||||||
criteriaQuery.setMinScore(2.0F);
|
criteriaQuery.setMinScore(2.0F);
|
||||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class, index);
|
Page<SampleEntity> page = operations.queryForPage(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(page.getTotalElements()).isEqualTo(1);
|
assertThat(page.getTotalElements()).isEqualTo(1);
|
||||||
@ -813,13 +820,13 @@ public class CriteriaQueryTests {
|
|||||||
IndexQuery indexQuery = new IndexQuery();
|
IndexQuery indexQuery = new IndexQuery();
|
||||||
indexQuery.setId(documentId);
|
indexQuery.setId(documentId);
|
||||||
indexQuery.setObject(sampleEntity);
|
indexQuery.setObject(sampleEntity);
|
||||||
elasticsearchTemplate.index(indexQuery, index);
|
operations.index(indexQuery, index);
|
||||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
operations.refresh(SampleEntity.class);
|
||||||
|
|
||||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("Hello World!"));
|
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").is("Hello World!"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
SampleEntity sampleEntity1 = elasticsearchTemplate.queryForObject(criteriaQuery, SampleEntity.class, index);
|
SampleEntity sampleEntity1 = operations.queryForObject(criteriaQuery, SampleEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(sampleEntity1).isNotNull();
|
assertThat(sampleEntity1).isNotNull();
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.core.query;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { CriteriaQueryTestsTransport.Config.class })
|
||||||
|
public class CriteriaQueryTestsTransport extends CriteriaQueryTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -31,11 +31,10 @@ import java.util.Optional;
|
|||||||
|
|
||||||
import org.apache.webbeans.cditest.CdiTestContainer;
|
import org.apache.webbeans.cditest.CdiTestContainer;
|
||||||
import org.apache.webbeans.cditest.CdiTestContainerLoader;
|
import org.apache.webbeans.cditest.CdiTestContainerLoader;
|
||||||
import org.junit.AfterClass;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
@ -56,7 +55,7 @@ public class CdiRepositoryTests {
|
|||||||
private SamplePersonRepository personRepository;
|
private SamplePersonRepository personRepository;
|
||||||
private QualifiedProductRepository qualifiedProductRepository;
|
private QualifiedProductRepository qualifiedProductRepository;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeAll
|
||||||
public static void init() throws Exception {
|
public static void init() throws Exception {
|
||||||
|
|
||||||
cdiContainer = CdiTestContainerLoader.getCdiContainer();
|
cdiContainer = CdiTestContainerLoader.getCdiContainer();
|
||||||
@ -64,14 +63,14 @@ public class CdiRepositoryTests {
|
|||||||
cdiContainer.bootContainer();
|
cdiContainer.bootContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterClass
|
@AfterAll
|
||||||
public static void shutdown() throws Exception {
|
public static void shutdown() throws Exception {
|
||||||
|
|
||||||
cdiContainer.stopContexts();
|
cdiContainer.stopContexts();
|
||||||
cdiContainer.shutdownContainer();
|
cdiContainer.shutdownContainer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|
||||||
CdiRepositoryClient client = cdiContainer.getInstance(CdiRepositoryClient.class);
|
CdiRepositoryClient client = cdiContainer.getInstance(CdiRepositoryClient.class);
|
||||||
|
@ -28,8 +28,8 @@ import org.springframework.context.annotation.Import;
|
|||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
||||||
@ -45,19 +45,17 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
public class ComplexCustomMethodRepositoryTests {
|
public class ComplexCustomMethodRepositoryTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({ ElasticsearchTemplateConfiguration.class })
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
@EnableElasticsearchRepositories(
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
basePackages = { "org.springframework.data.elasticsearch.repositories.complex.custommethod.autowiring" },
|
|
||||||
considerNestedRepositories = true)
|
|
||||||
static class Config {}
|
static class Config {}
|
||||||
|
|
||||||
@Autowired private ComplexElasticsearchRepository complexRepository;
|
@Autowired private ComplexElasticsearchRepository complexRepository;
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
IndexInitializer.init(elasticsearchTemplate, SampleEntity.class);
|
IndexInitializer.init(operations, SampleEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.repositories.complex.custommethod.autowiring;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { ComplexCustomMethodRepositoryTransportTests.Config.class })
|
||||||
|
public class ComplexCustomMethodRepositoryTransportTests extends ComplexCustomMethodRepositoryTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -1,18 +1,18 @@
|
|||||||
package org.springframework.data.elasticsearch.repositories.complex.custommethod.autowiring;
|
package org.springframework.data.elasticsearch.repositories.complex.custommethod.autowiring;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
*/
|
*/
|
||||||
public class ComplexElasticsearchRepositoryImpl implements ComplexElasticsearchRepositoryCustom {
|
public class ComplexElasticsearchRepositoryImpl implements ComplexElasticsearchRepositoryCustom {
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate template;
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String doSomethingSpecial() {
|
public String doSomethingSpecial() {
|
||||||
assert (template.getElasticsearchConverter() != null);
|
assert (operations.getElasticsearchConverter() != null);
|
||||||
return "2+2=4";
|
return "2+2=4";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,34 +20,41 @@ import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@SpringIntegrationTest
|
||||||
@ContextConfiguration("classpath:complex-custom-method-repository-manual-wiring-test.xml")
|
@ContextConfiguration(classes = { ComplexCustomMethodRepositoryManualWiringTests.Config.class })
|
||||||
public class ComplexCustomMethodRepositoryManualWiringTests {
|
public class ComplexCustomMethodRepositoryManualWiringTests {
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
|
||||||
@Autowired private ComplexElasticsearchRepositoryManualWiring complexRepository;
|
@Autowired private ComplexElasticsearchRepositoryManualWiring complexRepository;
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
IndexInitializer.init(elasticsearchTemplate, SampleEntity.class);
|
IndexInitializer.init(operations, SampleEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.repositories.complex.custommethod.manualwiring;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { ComplexCustomMethodRepositoryManualWiringTransportTests.Config.class })
|
||||||
|
public class ComplexCustomMethodRepositoryManualWiringTransportTests
|
||||||
|
extends ComplexCustomMethodRepositoryManualWiringTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -15,24 +15,25 @@
|
|||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.repositories.complex.custommethod.manualwiring;
|
package org.springframework.data.elasticsearch.repositories.complex.custommethod.manualwiring;
|
||||||
|
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.repositories.complex.custommethod.autowiring.ComplexElasticsearchRepositoryCustom;
|
import org.springframework.data.elasticsearch.repositories.complex.custommethod.autowiring.ComplexElasticsearchRepositoryCustom;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Artur Konczak
|
* @author Artur Konczak
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
public class ComplexElasticsearchRepositoryManualWiringImpl implements ComplexElasticsearchRepositoryCustom {
|
public class ComplexElasticsearchRepositoryManualWiringImpl implements ComplexElasticsearchRepositoryCustom {
|
||||||
|
|
||||||
private ElasticsearchTemplate template;
|
private ElasticsearchOperations operations;
|
||||||
|
|
||||||
|
public ComplexElasticsearchRepositoryManualWiringImpl(ElasticsearchOperations operations) {
|
||||||
|
this.operations = operations;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String doSomethingSpecial() {
|
public String doSomethingSpecial() {
|
||||||
assert (template.getElasticsearchConverter() != null);
|
assert (operations.getElasticsearchConverter() != null);
|
||||||
return "3+3=6";
|
return "3+3=6";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTemplate(ElasticsearchTemplate template) {
|
|
||||||
this.template = template;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import org.junit.jupiter.api.BeforeEach;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
||||||
@ -40,10 +40,10 @@ public class CustomMethodRepositoryTests extends CustomMethodRepositoryBaseTests
|
|||||||
considerNestedRepositories = true)
|
considerNestedRepositories = true)
|
||||||
static class Config {}
|
static class Config {}
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
IndexInitializer.init(elasticsearchTemplate, SampleEntity.class);
|
IndexInitializer.init(operations, SampleEntity.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,19 +21,22 @@ import java.util.Arrays;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.apache.commons.lang.math.RandomUtils;
|
import org.apache.commons.lang.math.RandomUtils;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.annotation.Version;
|
import org.springframework.data.annotation.Version;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
@ -42,23 +45,28 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@SpringIntegrationTest
|
||||||
@ContextConfiguration("classpath:/double-id-repository-test.xml")
|
@ContextConfiguration(classes = { DoubleIDRepositoryTests.Config.class })
|
||||||
public class DoubleIDRepositoryTests {
|
public class DoubleIDRepositoryTests {
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
|
||||||
@Autowired private DoubleIDRepository repository;
|
@Autowired private DoubleIDRepository repository;
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
IndexInitializer.init(elasticsearchTemplate, DoubleIDEntity.class);
|
IndexInitializer.init(operations, DoubleIDEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void after() {
|
public void after() {
|
||||||
|
|
||||||
elasticsearchTemplate.deleteIndex(DoubleIDEntity.class);
|
operations.deleteIndex(DoubleIDEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.repositories.doubleid;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { DoubleIDRepositoryTransportTests.Config.class })
|
||||||
|
public class DoubleIDRepositoryTransportTests extends DoubleIDRepositoryTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -17,20 +17,21 @@ package org.springframework.data.elasticsearch.repositories.dynamicindex;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ImportResource;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DynamicIndexEntityTests
|
* DynamicIndexEntityTests
|
||||||
@ -39,33 +40,43 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@SpringIntegrationTest
|
||||||
@ContextConfiguration(classes = DynamicIndexEntityTests.TestConfig.class)
|
@ContextConfiguration(classes = { DynamicIndexEntityTests.Config.class })
|
||||||
public class DynamicIndexEntityTests {
|
public class DynamicIndexEntityTests {
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {
|
||||||
|
@Bean
|
||||||
|
public IndexNameProvider indexNameProvider() {
|
||||||
|
return new IndexNameProvider();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Autowired private DynamicIndexRepository repository;
|
@Autowired private DynamicIndexRepository repository;
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate template;
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@Autowired private IndexNameProvider indexNameProvider;
|
@Autowired private IndexNameProvider indexNameProvider;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() {
|
public void init() {
|
||||||
|
|
||||||
deleteIndexes();
|
deleteIndexes();
|
||||||
template.createIndex("index1");
|
operations.createIndex("index1");
|
||||||
template.createIndex("index2");
|
operations.createIndex("index2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void teardown() {
|
public void teardown() {
|
||||||
deleteIndexes();
|
deleteIndexes();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteIndexes() {
|
private void deleteIndexes() {
|
||||||
|
|
||||||
template.deleteIndex("index1");
|
operations.deleteIndex("index1");
|
||||||
template.deleteIndex("index2");
|
operations.deleteIndex("index2");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-456
|
@Test // DATAES-456
|
||||||
@ -82,16 +93,6 @@ public class DynamicIndexEntityTests {
|
|||||||
assertThat(repository.count()).isEqualTo(0L);
|
assertThat(repository.count()).isEqualTo(0L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ImportResource(value = "classpath:/dynamic-index-repository-test.xml")
|
|
||||||
static class TestConfig {
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public IndexNameProvider indexNameProvider() {
|
|
||||||
return new IndexNameProvider();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static class IndexNameProvider {
|
static class IndexNameProvider {
|
||||||
|
|
||||||
private String indexName;
|
private String indexName;
|
||||||
|
@ -13,26 +13,22 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.springframework.data.elasticsearch.repository.query.keywords;
|
package org.springframework.data.elasticsearch.repositories.dynamicindex;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link QueryKeywordsTests} using a Repository backed by an ElasticsearchRestTemplate.
|
|
||||||
*
|
|
||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
@ContextConfiguration(classes = { QueryKeywordsRestRepositoryTests.Config.class })
|
@ContextConfiguration(classes = { DynamicIndexEntityTransportTests.Config.class })
|
||||||
public class QueryKeywordsRestRepositoryTests extends QueryKeywordsTests {
|
|
||||||
|
|
||||||
|
public class DynamicIndexEntityTransportTests extends DynamicIndexEntityTests {
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
@EnableElasticsearchRepositories(
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
basePackages = { "org.springframework.data.elasticsearch.repository.query.keywords" },
|
|
||||||
considerNestedRepositories = true)
|
|
||||||
static class Config {}
|
static class Config {}
|
||||||
}
|
}
|
@ -34,9 +34,9 @@ import org.springframework.context.annotation.Import;
|
|||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.GeoPointField;
|
import org.springframework.data.elasticsearch.annotations.GeoPointField;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
@ -57,18 +57,17 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
public class SpringDataGeoRepositoryTests {
|
public class SpringDataGeoRepositoryTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({ ElasticsearchTemplateConfiguration.class })
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
@EnableElasticsearchRepositories(basePackages = { "org.springframework.data.elasticsearch.repositories.geo" },
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
considerNestedRepositories = true)
|
|
||||||
static class Config {}
|
static class Config {}
|
||||||
|
|
||||||
@Autowired ElasticsearchTemplate template;
|
@Autowired ElasticsearchOperations operations;
|
||||||
|
|
||||||
@Autowired SpringDataGeoRepository repository;
|
@Autowired SpringDataGeoRepository repository;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void init() {
|
public void init() {
|
||||||
IndexInitializer.init(template, GeoEntity.class);
|
IndexInitializer.init(operations, GeoEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.repositories.geo;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { SpringDataGeoRepositoryTransportTests.Config.class })
|
||||||
|
public class SpringDataGeoRepositoryTransportTests extends SpringDataGeoRepositoryTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -21,18 +21,21 @@ import java.util.Arrays;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.apache.commons.lang.math.RandomUtils;
|
import org.apache.commons.lang.math.RandomUtils;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.annotation.Version;
|
import org.springframework.data.annotation.Version;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
@ -41,17 +44,22 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@SpringIntegrationTest
|
||||||
@ContextConfiguration("classpath:/integer-id-repository-test.xml")
|
@ContextConfiguration(classes = { IntegerIDRepositoryTests.Config.class })
|
||||||
public class IntegerIDRepositoryTests {
|
public class IntegerIDRepositoryTests {
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
|
||||||
@Autowired private IntegerIDRepository repository;
|
@Autowired private IntegerIDRepository repository;
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
IndexInitializer.init(elasticsearchTemplate, IntegerIDEntity.class);
|
IndexInitializer.init(operations, IntegerIDEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.repositories.integer;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { IntegerIDRepositoryTransportTests.Config.class })
|
||||||
|
public class IntegerIDRepositoryTransportTests extends IntegerIDRepositoryTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -29,38 +29,46 @@ import java.util.Collection;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||||
import org.springframework.data.elasticsearch.annotations.InnerField;
|
import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@SpringIntegrationTest
|
||||||
@ContextConfiguration("classpath:/repository-test-nested-object-books.xml")
|
@ContextConfiguration(classes = { InnerObjectTests.Config.class })
|
||||||
public class InnerObjectTests {
|
public class InnerObjectTests {
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
|
||||||
@Autowired private SampleElasticSearchBookRepository bookRepository;
|
@Autowired private SampleElasticSearchBookRepository bookRepository;
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
IndexInitializer.init(elasticsearchTemplate, Book.class);
|
IndexInitializer.init(operations, Book.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.repositories.nestedobject;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { InnerObjectTransportTests.Config.class })
|
||||||
|
public class InnerObjectTransportTests extends InnerObjectTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -31,11 +31,11 @@ import org.springframework.data.annotation.Id;
|
|||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Mapping;
|
import org.springframework.data.elasticsearch.annotations.Mapping;
|
||||||
import org.springframework.data.elasticsearch.annotations.Setting;
|
import org.springframework.data.elasticsearch.annotations.Setting;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;
|
||||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
@ -54,19 +54,17 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
public class DynamicSettingAndMappingEntityRepositoryTests {
|
public class DynamicSettingAndMappingEntityRepositoryTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({ ElasticsearchTemplateConfiguration.class })
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
@EnableElasticsearchRepositories(
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
basePackages = { "org.springframework.data.elasticsearch.repositories.setting.dynamic" },
|
|
||||||
considerNestedRepositories = true)
|
|
||||||
static class Config {}
|
static class Config {}
|
||||||
|
|
||||||
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@Autowired private DynamicSettingAndMappingEntityRepository repository;
|
@Autowired private DynamicSettingAndMappingEntityRepository repository;
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
IndexInitializer.init(elasticsearchTemplate, DynamicSettingAndMappingEntity.class);
|
IndexInitializer.init(operations, DynamicSettingAndMappingEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-64
|
@Test // DATAES-64
|
||||||
@ -76,8 +74,8 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
|||||||
// delete , create and apply mapping in before method
|
// delete , create and apply mapping in before method
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(elasticsearchTemplate.indexExists(DynamicSettingAndMappingEntity.class)).isTrue();
|
assertThat(operations.indexExists(DynamicSettingAndMappingEntity.class)).isTrue();
|
||||||
Map<String, Object> map = elasticsearchTemplate.getSetting(DynamicSettingAndMappingEntity.class);
|
Map<String, Object> map = operations.getSetting(DynamicSettingAndMappingEntity.class);
|
||||||
assertThat(map.containsKey("index.number_of_replicas")).isTrue();
|
assertThat(map.containsKey("index.number_of_replicas")).isTrue();
|
||||||
assertThat(map.containsKey("index.number_of_shards")).isTrue();
|
assertThat(map.containsKey("index.number_of_shards")).isTrue();
|
||||||
assertThat(map.containsKey("index.analysis.analyzer.emailAnalyzer.tokenizer")).isTrue();
|
assertThat(map.containsKey("index.analysis.analyzer.emailAnalyzer.tokenizer")).isTrue();
|
||||||
@ -108,10 +106,10 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
|||||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
|
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||||
.withQuery(QueryBuilders.termQuery("email", dynamicSettingAndMappingEntity1.getEmail())).build();
|
.withQuery(QueryBuilders.termQuery("email", dynamicSettingAndMappingEntity1.getEmail())).build();
|
||||||
|
|
||||||
IndexCoordinates index = IndexCoordinates.of("test-index-dynamic-setting-and-mapping").withTypes( "test-setting-type");
|
IndexCoordinates index = IndexCoordinates.of("test-index-dynamic-setting-and-mapping")
|
||||||
long count = elasticsearchTemplate.count(searchQuery, DynamicSettingAndMappingEntity.class,
|
.withTypes("test-setting-type");
|
||||||
index);
|
long count = operations.count(searchQuery, DynamicSettingAndMappingEntity.class, index);
|
||||||
List<DynamicSettingAndMappingEntity> entityList = elasticsearchTemplate.queryForList(searchQuery,
|
List<DynamicSettingAndMappingEntity> entityList = operations.queryForList(searchQuery,
|
||||||
DynamicSettingAndMappingEntity.class, index);
|
DynamicSettingAndMappingEntity.class, index);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -127,7 +125,7 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
|||||||
// delete , create and apply mapping in before method
|
// delete , create and apply mapping in before method
|
||||||
|
|
||||||
// when
|
// when
|
||||||
Map<String, Object> mapping = elasticsearchTemplate.getMapping(DynamicSettingAndMappingEntity.class);
|
Map<String, Object> mapping = operations.getMapping(DynamicSettingAndMappingEntity.class);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
Map<String, Object> properties = (Map<String, Object>) mapping.get("properties");
|
Map<String, Object> properties = (Map<String, Object>) mapping.get("properties");
|
||||||
@ -142,9 +140,9 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
|||||||
public void shouldCreateMappingWithSpecifiedMappings() {
|
public void shouldCreateMappingWithSpecifiedMappings() {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
elasticsearchTemplate.deleteIndex(DynamicSettingAndMappingEntity.class);
|
operations.deleteIndex(DynamicSettingAndMappingEntity.class);
|
||||||
elasticsearchTemplate.createIndex(DynamicSettingAndMappingEntity.class);
|
operations.createIndex(DynamicSettingAndMappingEntity.class);
|
||||||
elasticsearchTemplate.refresh(DynamicSettingAndMappingEntity.class);
|
operations.refresh(DynamicSettingAndMappingEntity.class);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
String mappings = "{\n" + //
|
String mappings = "{\n" + //
|
||||||
@ -154,11 +152,11 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
|||||||
" }\n" + //
|
" }\n" + //
|
||||||
" }\n" + //
|
" }\n" + //
|
||||||
"}";
|
"}";
|
||||||
elasticsearchTemplate.putMapping(DynamicSettingAndMappingEntity.class, mappings);
|
operations.putMapping(DynamicSettingAndMappingEntity.class, mappings);
|
||||||
elasticsearchTemplate.refresh(DynamicSettingAndMappingEntity.class);
|
operations.refresh(DynamicSettingAndMappingEntity.class);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
Map<String, Object> mapping = elasticsearchTemplate.getMapping(DynamicSettingAndMappingEntity.class);
|
Map<String, Object> mapping = operations.getMapping(DynamicSettingAndMappingEntity.class);
|
||||||
Map<String, Object> properties = (Map<String, Object>) mapping.get("properties");
|
Map<String, Object> properties = (Map<String, Object>) mapping.get("properties");
|
||||||
assertThat(mapping).isNotNull();
|
assertThat(mapping).isNotNull();
|
||||||
assertThat(properties).isNotNull();
|
assertThat(properties).isNotNull();
|
||||||
@ -173,7 +171,7 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
|||||||
// given
|
// given
|
||||||
|
|
||||||
// then
|
// then
|
||||||
Map<String, Object> mapping = elasticsearchTemplate.getMapping(DynamicSettingAndMappingEntity.class);
|
Map<String, Object> mapping = operations.getMapping(DynamicSettingAndMappingEntity.class);
|
||||||
Map<String, Object> properties = (Map<String, Object>) mapping.get("properties");
|
Map<String, Object> properties = (Map<String, Object>) mapping.get("properties");
|
||||||
assertThat(mapping).isNotNull();
|
assertThat(mapping).isNotNull();
|
||||||
assertThat(properties).isNotNull();
|
assertThat(properties).isNotNull();
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.repositories.setting.dynamic;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { DynamicSettingAndMappingEntityRepositoryTransportTests.Config.class })
|
||||||
|
public class DynamicSettingAndMappingEntityRepositoryTransportTests
|
||||||
|
extends DynamicSettingAndMappingEntityRepositoryTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -27,8 +27,8 @@ import org.springframework.context.annotation.Import;
|
|||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Mapping;
|
import org.springframework.data.elasticsearch.annotations.Mapping;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;
|
||||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
@ -46,19 +46,17 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
public class FieldDynamicMappingEntityRepositoryTests {
|
public class FieldDynamicMappingEntityRepositoryTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({ ElasticsearchTemplateConfiguration.class })
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
@EnableElasticsearchRepositories(
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
basePackages = { "org.springframework.data.elasticsearch.repositories.setting.fielddynamic" },
|
|
||||||
considerNestedRepositories = true)
|
|
||||||
static class Config {}
|
static class Config {}
|
||||||
|
|
||||||
@Autowired private FieldDynamicMappingEntityRepository repository;
|
@Autowired private FieldDynamicMappingEntityRepository repository;
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
IndexInitializer.init(elasticsearchTemplate, FieldDynamicMappingEntity.class);
|
IndexInitializer.init(operations, FieldDynamicMappingEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-209
|
@Test // DATAES-209
|
||||||
@ -67,7 +65,7 @@ public class FieldDynamicMappingEntityRepositoryTests {
|
|||||||
// given
|
// given
|
||||||
|
|
||||||
// then
|
// then
|
||||||
Map<String, Object> mapping = elasticsearchTemplate.getMapping(FieldDynamicMappingEntity.class);
|
Map<String, Object> mapping = operations.getMapping(FieldDynamicMappingEntity.class);
|
||||||
assertThat(mapping).isNotNull();
|
assertThat(mapping).isNotNull();
|
||||||
|
|
||||||
Map<String, Object> properties = (Map<String, Object>) mapping.get("properties");
|
Map<String, Object> properties = (Map<String, Object>) mapping.get("properties");
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.repositories.setting.fielddynamic;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { FieldDynamicMappingEntityRepositoryTransportTests.Config.class })
|
||||||
|
public class FieldDynamicMappingEntityRepositoryTransportTests extends FieldDynamicMappingEntityRepositoryTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -25,10 +25,10 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.context.annotation.Import;
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
@ -45,18 +45,18 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
@ContextConfiguration(classes = { SpELEntityTests.Config.class })
|
@ContextConfiguration(classes = { SpELEntityTests.Config.class })
|
||||||
public class SpELEntityTests {
|
public class SpELEntityTests {
|
||||||
|
|
||||||
@Autowired private SpELRepository repository;
|
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate template;
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import(ElasticsearchTemplateConfiguration.class)
|
@Import(ElasticsearchRestTemplateConfiguration.class)
|
||||||
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
static class Config {}
|
static class Config {}
|
||||||
|
|
||||||
|
@Autowired private SpELRepository repository;
|
||||||
|
|
||||||
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
IndexInitializer.init(template, SpELEntity.class);
|
IndexInitializer.init(operations, SpELEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -70,7 +70,7 @@ public class SpELEntityTests {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery());
|
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery());
|
||||||
long count = template.count(nativeSearchQuery, IndexCoordinates.of("test-index-abz-entity"));
|
long count = operations.count(nativeSearchQuery, IndexCoordinates.of("test-index-abz-entity"));
|
||||||
assertThat(count).isEqualTo(2);
|
assertThat(count).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ public class SpELEntityTests {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery());
|
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery());
|
||||||
long count = template.count(nativeSearchQuery, IndexCoordinates.of("test-index-abz-entity"));
|
long count = operations.count(nativeSearchQuery, IndexCoordinates.of("test-index-abz-entity"));
|
||||||
assertThat(count).isEqualTo(1);
|
assertThat(count).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.repositories.spel;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { SpELEntityTransportTests.Config.class })
|
||||||
|
public class SpELEntityTransportTests extends SpELEntityTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -31,10 +31,10 @@ import org.springframework.data.annotation.Id;
|
|||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Mapping;
|
import org.springframework.data.elasticsearch.annotations.Mapping;
|
||||||
import org.springframework.data.elasticsearch.annotations.Setting;
|
import org.springframework.data.elasticsearch.annotations.Setting;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
import org.springframework.data.elasticsearch.core.IndexCoordinates;
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchCrudRepository;
|
||||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
@ -52,18 +52,17 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
public class SynonymRepositoryTests {
|
public class SynonymRepositoryTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({ ElasticsearchTemplateConfiguration.class })
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
@EnableElasticsearchRepositories(basePackages = { "org.springframework.data.elasticsearch.repositories.synonym" },
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
considerNestedRepositories = true)
|
|
||||||
static class Config {}
|
static class Config {}
|
||||||
|
|
||||||
@Autowired private SynonymRepository repository;
|
@Autowired private SynonymRepository repository;
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
IndexInitializer.init(elasticsearchTemplate, SynonymEntity.class);
|
IndexInitializer.init(operations, SynonymEntity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -83,9 +82,9 @@ public class SynonymRepositoryTests {
|
|||||||
// then
|
// then
|
||||||
assertThat(repository.count()).isEqualTo(2L);
|
assertThat(repository.count()).isEqualTo(2L);
|
||||||
|
|
||||||
List<SynonymEntity> synonymEntities = elasticsearchTemplate.queryForList(
|
List<SynonymEntity> synonymEntities = operations.queryForList(
|
||||||
new NativeSearchQueryBuilder().withQuery(QueryBuilders.termQuery("text", "british")).build(),
|
new NativeSearchQueryBuilder().withQuery(QueryBuilders.termQuery("text", "british")).build(),
|
||||||
SynonymEntity.class, IndexCoordinates.of("test-index-synonym").withTypes( "synonym-type"));
|
SynonymEntity.class, IndexCoordinates.of("test-index-synonym").withTypes("synonym-type"));
|
||||||
assertThat(synonymEntities).hasSize(1);
|
assertThat(synonymEntities).hasSize(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.repositories.synonym;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { SynonymRepositoryTransportTests.Config.class })
|
||||||
|
public class SynonymRepositoryTransportTests extends SynonymRepositoryTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -44,11 +44,11 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
|||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||||
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
|
||||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
@ -69,19 +69,18 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
public class UUIDElasticsearchRepositoryTests {
|
public class UUIDElasticsearchRepositoryTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({ ElasticsearchTemplateConfiguration.class })
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
@EnableElasticsearchRepositories(basePackages = { "org.springframework.data.elasticsearch.repositories.uuidkeyed" },
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
considerNestedRepositories = true)
|
|
||||||
static class Config {}
|
static class Config {}
|
||||||
|
|
||||||
@Autowired private SampleUUIDKeyedElasticsearchRepository repository;
|
@Autowired private SampleUUIDKeyedElasticsearchRepository repository;
|
||||||
|
|
||||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
@Autowired private ElasticsearchOperations operations;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() {
|
public void before() {
|
||||||
|
|
||||||
IndexInitializer.init(elasticsearchTemplate, SampleEntityUUIDKeyed.class);
|
IndexInitializer.init(operations, SampleEntityUUIDKeyed.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2019 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.data.elasticsearch.repositories.uuidkeyed;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchTemplateConfiguration;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
|
*/
|
||||||
|
@ContextConfiguration(classes = { UUIDElasticsearchRepositoryTransportTests.Config.class })
|
||||||
|
public class UUIDElasticsearchRepositoryTransportTests extends UUIDElasticsearchRepositoryTests {
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
}
|
@ -23,9 +23,7 @@ import lombok.Data;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
import org.assertj.core.api.Assertions;
|
import org.assertj.core.api.Assertions;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
@ -35,17 +33,16 @@ import org.springframework.data.elasticsearch.TestUtils;
|
|||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
|
import org.springframework.data.elasticsearch.core.ReactiveElasticsearchTemplate;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ReactiveElasticsearchRepository;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @currentRead Fool's Fate - Robin Hobb
|
|
||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@SpringIntegrationTest
|
||||||
@ContextConfiguration
|
@ContextConfiguration(classes = { ReactiveElasticsearchRepositoriesRegistrarTests.Config.class })
|
||||||
public class ReactiveElasticsearchRepositoriesRegistrarTests {
|
public class ReactiveElasticsearchRepositoriesRegistrarTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
|
@ -19,8 +19,7 @@ import static org.assertj.core.api.Assertions.*;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
@ -37,7 +36,7 @@ import org.springframework.data.repository.reactive.ReactiveCrudRepository;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @currentRead Fool's Fate - Robin Hobb
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
public class ReactiveElasticsearchRepositoryConfigurationExtensionUnitTests {
|
public class ReactiveElasticsearchRepositoryConfigurationExtensionUnitTests {
|
||||||
|
|
||||||
|
@ -26,13 +26,11 @@ import org.springframework.test.context.ContextConfiguration;
|
|||||||
*
|
*
|
||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
@ContextConfiguration(classes = { QueryKeywordsRepositoryTests.Config.class})
|
@ContextConfiguration(classes = { QueryKeywordsRepositoryTransportTests.Config.class })
|
||||||
public class QueryKeywordsRepositoryTests extends QueryKeywordsTests {
|
public class QueryKeywordsRepositoryTransportTests extends QueryKeywordsTests {
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@Import({ ElasticsearchTemplateConfiguration.class })
|
@Import({ ElasticsearchTemplateConfiguration.class })
|
||||||
@EnableElasticsearchRepositories(
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
basePackages = { "org.springframework.data.elasticsearch.repository.query.keywords" },
|
|
||||||
considerNestedRepositories = true)
|
|
||||||
static class Config {}
|
static class Config {}
|
||||||
}
|
}
|
@ -31,14 +31,19 @@ import java.util.stream.Collectors;
|
|||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
import org.springframework.data.elasticsearch.annotations.Field;
|
import org.springframework.data.elasticsearch.annotations.Field;
|
||||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||||
|
import org.springframework.data.elasticsearch.junit.jupiter.ElasticsearchRestTemplateConfiguration;
|
||||||
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
import org.springframework.data.elasticsearch.junit.jupiter.SpringIntegrationTest;
|
||||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||||
|
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
|
||||||
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* base class for query keyword tests. Implemented by subclasses using ElasticsearchClient and ElasticsearchRestClient
|
* base class for query keyword tests. Implemented by subclasses using ElasticsearchClient and ElasticsearchRestClient
|
||||||
@ -49,7 +54,13 @@ import org.springframework.data.elasticsearch.utils.IndexInitializer;
|
|||||||
* @author Peter-Josef Meisch
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
@SpringIntegrationTest
|
@SpringIntegrationTest
|
||||||
abstract class QueryKeywordsTests {
|
@ContextConfiguration(classes = { QueryKeywordsTests.Config.class })
|
||||||
|
class QueryKeywordsTests {
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Import({ ElasticsearchRestTemplateConfiguration.class })
|
||||||
|
@EnableElasticsearchRepositories(considerNestedRepositories = true)
|
||||||
|
static class Config {}
|
||||||
|
|
||||||
@Autowired private ProductRepository repository;
|
@Autowired private ProductRepository repository;
|
||||||
|
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
|
||||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
|
||||||
<constructor-arg name="client" ref="client"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<elasticsearch:repositories
|
|
||||||
base-package="org.springframework.data.elasticsearch.repositories.complex.custommethod.manualwiring"/>
|
|
||||||
|
|
||||||
<bean id="complexElasticsearchRepositoryManualWiringImpl"
|
|
||||||
class="org.springframework.data.elasticsearch.repositories.complex.custommethod.manualwiring.ComplexElasticsearchRepositoryManualWiringImpl">
|
|
||||||
<property name="template" ref="elasticsearchTemplate"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
</beans>
|
|
@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
|
||||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
|
||||||
<constructor-arg name="client" ref="client"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<elasticsearch:repositories
|
|
||||||
base-package="org.springframework.data.elasticsearch.repositories.doubleid"
|
|
||||||
consider-nested-repositories="true"/>
|
|
||||||
|
|
||||||
</beans>
|
|
@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
|
||||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
|
||||||
<constructor-arg name="client" ref="client"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<elasticsearch:repositories
|
|
||||||
base-package="org.springframework.data.elasticsearch.repositories.dynamicindex"
|
|
||||||
consider-nested-repositories="true"/>
|
|
||||||
|
|
||||||
</beans>
|
|
@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
|
||||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
|
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate">
|
|
||||||
<constructor-arg name="client" ref="restClient"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<elasticsearch:rest-client id="restClient"/>
|
|
||||||
|
|
||||||
</beans>
|
|
@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
|
||||||
<constructor-arg name="client" ref="client"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
</beans>
|
|
@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
|
||||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
|
||||||
<constructor-arg name="client" ref="client"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<elasticsearch:repositories
|
|
||||||
base-package="org.springframework.data.elasticsearch.repositories.existing.index"
|
|
||||||
consider-nested-repositories="true" />
|
|
||||||
|
|
||||||
</beans>
|
|
@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
|
||||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
|
||||||
<constructor-arg name="client" ref="client"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<elasticsearch:repositories
|
|
||||||
base-package="org.springframework.data.elasticsearch.repositories.setting.fielddynamic"
|
|
||||||
consider-nested-repositories="true"/>
|
|
||||||
|
|
||||||
</beans>
|
|
@ -1,18 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
|
||||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd">
|
|
||||||
|
|
||||||
<elasticsearch:node-client id="client" local="true" cluster-name="#{T(java.util.UUID).randomUUID().toString()}"
|
|
||||||
http-enabled="true" path-data="target/elasticsearchTestData" path-home="src/test/resources/test-home-dir"
|
|
||||||
path-configuration="node-client-configuration.yml"/>
|
|
||||||
|
|
||||||
<!-- ip4 -->
|
|
||||||
<!--<elasticsearch:transport-client id="client" cluster-name="elasticsearch" cluster-nodes="127.0.0.1:9300" />-->
|
|
||||||
|
|
||||||
<!-- ip6 -->
|
|
||||||
<!--<elasticsearch:transport-client id="client" cluster-name="elasticsearch" cluster-nodes="[::1]:9300" />-->
|
|
||||||
|
|
||||||
</beans>
|
|
@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
|
||||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
|
||||||
<constructor-arg name="client" ref="client"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<elasticsearch:repositories
|
|
||||||
base-package="org.springframework.data.elasticsearch.repositories.integer"
|
|
||||||
consider-nested-repositories="true" />
|
|
||||||
|
|
||||||
</beans>
|
|
@ -1,19 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
||||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
<elasticsearch:node-client id="client" local="true" cluster-name="#{T(java.util.UUID).randomUUID().toString()}"
|
||||||
|
http-enabled="true" path-data="target/elasticsearchTestData" path-home="src/test/resources/test-home-dir"
|
||||||
|
path-configuration="node-client-configuration.yml"/>
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
<bean name="elasticsearchTemplate"
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
||||||
<constructor-arg name="client" ref="client"/>
|
<constructor-arg name="client" ref="client"/>
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<elasticsearch:repositories
|
<elasticsearch:repositories
|
||||||
base-package="org.springframework.data.elasticsearch.repositories.nondocument"
|
base-package="org.springframework.data.elasticsearch.repositories.nondocument"
|
||||||
consider-nested-repositories="true"/>
|
consider-nested-repositories="true"/>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
|
||||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
|
||||||
<constructor-arg name="client" ref="client"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<elasticsearch:repositories base-package="org.springframework.data.elasticsearch.repositories.nestedobject"
|
|
||||||
consider-nested-repositories="true"/>
|
|
||||||
|
|
||||||
</beans>
|
|
@ -1,17 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
|
||||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
|
||||||
<constructor-arg name="client" ref="client"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<elasticsearch:repositories base-package="org.springframework.data.elasticsearch"/>
|
|
||||||
|
|
||||||
</beans>
|
|
@ -1,19 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
|
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch https://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch.xsd
|
|
||||||
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
|
|
||||||
|
|
||||||
<import resource="infrastructure.xml"/>
|
|
||||||
|
|
||||||
<bean name="elasticsearchTemplate"
|
|
||||||
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
|
|
||||||
<constructor-arg name="client" ref="client"/>
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<elasticsearch:repositories
|
|
||||||
base-package="org.springframework.data.elasticsearch.repositories.synonym"
|
|
||||||
consider-nested-repositories="true"/>
|
|
||||||
|
|
||||||
</beans>
|
|
Loading…
x
Reference in New Issue
Block a user