DATAES-424 - Fix line endings to LF.
This commit is contained in:
@@ -1,73 +1,73 @@
|
||||
/*
|
||||
* Copyright 2014-2017 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
|
||||
*
|
||||
* http://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;
|
||||
|
||||
import static org.apache.commons.lang.RandomStringUtils.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.entities.Author;
|
||||
import org.springframework.data.elasticsearch.entities.Book;
|
||||
import org.springframework.data.elasticsearch.repositories.book.SampleElasticSearchBookRepository;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/repository-test-nested-object-books.xml")
|
||||
public class InnerObjectTests {
|
||||
|
||||
@Autowired private SampleElasticSearchBookRepository bookRepository;
|
||||
|
||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
elasticsearchTemplate.deleteIndex(Book.class);
|
||||
elasticsearchTemplate.createIndex(Book.class);
|
||||
elasticsearchTemplate.putMapping(Book.class);
|
||||
elasticsearchTemplate.refresh(Book.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldIndexInnerObject() {
|
||||
// given
|
||||
String id = randomAlphanumeric(5);
|
||||
Book book = new Book();
|
||||
book.setId(id);
|
||||
book.setName("xyz");
|
||||
Author author = new Author();
|
||||
author.setId("1");
|
||||
author.setName("ABC");
|
||||
book.setAuthor(author);
|
||||
// when
|
||||
bookRepository.save(book);
|
||||
// then
|
||||
assertThat(bookRepository.findById(id), is(notNullValue()));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2014-2017 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
|
||||
*
|
||||
* http://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;
|
||||
|
||||
import static org.apache.commons.lang.RandomStringUtils.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.entities.Author;
|
||||
import org.springframework.data.elasticsearch.entities.Book;
|
||||
import org.springframework.data.elasticsearch.repositories.book.SampleElasticSearchBookRepository;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/repository-test-nested-object-books.xml")
|
||||
public class InnerObjectTests {
|
||||
|
||||
@Autowired private SampleElasticSearchBookRepository bookRepository;
|
||||
|
||||
@Autowired private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
elasticsearchTemplate.deleteIndex(Book.class);
|
||||
elasticsearchTemplate.createIndex(Book.class);
|
||||
elasticsearchTemplate.putMapping(Book.class);
|
||||
elasticsearchTemplate.refresh(Book.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldIndexInnerObject() {
|
||||
// given
|
||||
String id = randomAlphanumeric(5);
|
||||
Book book = new Book();
|
||||
book.setId(id);
|
||||
book.setName("xyz");
|
||||
Author author = new Author();
|
||||
author.setId("1");
|
||||
author.setName("ABC");
|
||||
book.setAuthor(author);
|
||||
// when
|
||||
bookRepository.save(book);
|
||||
// then
|
||||
assertThat(bookRepository.findById(id), is(notNullValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,385 +1,385 @@
|
||||
/*
|
||||
* Copyright 2013-2017 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
|
||||
*
|
||||
* http://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;
|
||||
|
||||
import static org.apache.commons.lang.RandomStringUtils.*;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.core.query.GetQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||
import org.springframework.data.elasticsearch.entities.Author;
|
||||
import org.springframework.data.elasticsearch.entities.Book;
|
||||
import org.springframework.data.elasticsearch.entities.Car;
|
||||
import org.springframework.data.elasticsearch.entities.GirlFriend;
|
||||
import org.springframework.data.elasticsearch.entities.Person;
|
||||
import org.springframework.data.elasticsearch.entities.PersonMultipleLevelNested;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/repository-test-nested-object.xml")
|
||||
public class NestedObjectTests {
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
elasticsearchTemplate.deleteIndex(Book.class);
|
||||
elasticsearchTemplate.createIndex(Book.class);
|
||||
elasticsearchTemplate.putMapping(Book.class);
|
||||
elasticsearchTemplate.refresh(Book.class);
|
||||
elasticsearchTemplate.deleteIndex(Person.class);
|
||||
elasticsearchTemplate.createIndex(Person.class);
|
||||
elasticsearchTemplate.putMapping(Person.class);
|
||||
elasticsearchTemplate.refresh(Person.class);
|
||||
elasticsearchTemplate.deleteIndex(PersonMultipleLevelNested.class);
|
||||
elasticsearchTemplate.createIndex(PersonMultipleLevelNested.class);
|
||||
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
||||
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldIndexInitialLevelNestedObject() {
|
||||
|
||||
final List<Car> cars = new ArrayList<>();
|
||||
|
||||
final Car saturn = new Car();
|
||||
saturn.setName("Saturn");
|
||||
saturn.setModel("SL");
|
||||
|
||||
final Car subaru = new Car();
|
||||
subaru.setName("Subaru");
|
||||
subaru.setModel("Imprezza");
|
||||
|
||||
final Car ford = new Car();
|
||||
ford.setName("Ford");
|
||||
ford.setModel("Focus");
|
||||
|
||||
cars.add(saturn);
|
||||
cars.add(subaru);
|
||||
cars.add(ford);
|
||||
|
||||
final Person foo = new Person();
|
||||
foo.setName("Foo");
|
||||
foo.setId("1");
|
||||
foo.setCar(cars);
|
||||
|
||||
final Car car = new Car();
|
||||
car.setName("Saturn");
|
||||
car.setModel("Imprezza");
|
||||
|
||||
final Person bar = new Person();
|
||||
bar.setId("2");
|
||||
bar.setName("Bar");
|
||||
bar.setCar(Arrays.asList(car));
|
||||
|
||||
final List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
final IndexQuery indexQuery1 = new IndexQuery();
|
||||
indexQuery1.setId(foo.getId());
|
||||
indexQuery1.setObject(foo);
|
||||
|
||||
final IndexQuery indexQuery2 = new IndexQuery();
|
||||
indexQuery2.setId(bar.getId());
|
||||
indexQuery2.setObject(bar);
|
||||
|
||||
indexQueries.add(indexQuery1);
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
elasticsearchTemplate.putMapping(Person.class);
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(Person.class);
|
||||
|
||||
final QueryBuilder builder = nestedQuery("car", boolQuery().must(termQuery("car.name", "saturn")).must(termQuery("car.model", "imprezza")), ScoreMode.None);
|
||||
|
||||
final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
|
||||
final List<Person> persons = elasticsearchTemplate.queryForList(searchQuery, Person.class);
|
||||
|
||||
assertThat(persons.size(), is(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldIndexMultipleLevelNestedObject() {
|
||||
//given
|
||||
final List<IndexQuery> indexQueries = createPerson();
|
||||
|
||||
//when
|
||||
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
||||
|
||||
//then
|
||||
final GetQuery getQuery = new GetQuery();
|
||||
getQuery.setId("1");
|
||||
final PersonMultipleLevelNested personIndexed = elasticsearchTemplate.queryForObject(getQuery, PersonMultipleLevelNested.class);
|
||||
assertThat(personIndexed, is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldIndexMultipleLevelNestedObjectWithIncludeInParent() {
|
||||
//given
|
||||
final List<IndexQuery> indexQueries = createPerson();
|
||||
|
||||
//when
|
||||
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
// then
|
||||
|
||||
final Map mapping = elasticsearchTemplate.getMapping(PersonMultipleLevelNested.class);
|
||||
|
||||
assertThat(mapping, is(notNullValue()));
|
||||
final Map propertyMap = (Map) mapping.get("properties");
|
||||
assertThat(propertyMap, is(notNullValue()));
|
||||
final Map bestCarsAttributes = (Map) propertyMap.get("bestCars");
|
||||
assertThat(bestCarsAttributes.get("include_in_parent"), is(notNullValue()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldSearchUsingNestedQueryOnMultipleLevelNestedObject() {
|
||||
//given
|
||||
final List<IndexQuery> indexQueries = createPerson();
|
||||
|
||||
//when
|
||||
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
||||
|
||||
//then
|
||||
final BoolQueryBuilder builder = boolQuery();
|
||||
builder.must(nestedQuery("girlFriends", termQuery("girlFriends.type", "temp"),ScoreMode.None))
|
||||
.must(nestedQuery("girlFriends.cars", termQuery("girlFriends.cars.name", "Ford".toLowerCase()),ScoreMode.None));
|
||||
|
||||
final SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(builder)
|
||||
.build();
|
||||
|
||||
final Page<PersonMultipleLevelNested> personIndexed = elasticsearchTemplate.queryForPage(searchQuery, PersonMultipleLevelNested.class);
|
||||
assertThat(personIndexed, is(notNullValue()));
|
||||
assertThat(personIndexed.getTotalElements(), is(1L));
|
||||
assertThat(personIndexed.getContent().get(0).getId(), is("1"));
|
||||
}
|
||||
|
||||
|
||||
private List<IndexQuery> createPerson() {
|
||||
|
||||
final PersonMultipleLevelNested person1 = new PersonMultipleLevelNested();
|
||||
|
||||
person1.setId("1");
|
||||
person1.setName("name");
|
||||
|
||||
final Car saturn = new Car();
|
||||
saturn.setName("Saturn");
|
||||
saturn.setModel("SL");
|
||||
|
||||
final Car subaru = new Car();
|
||||
subaru.setName("Subaru");
|
||||
subaru.setModel("Imprezza");
|
||||
|
||||
final Car car = new Car();
|
||||
car.setName("Saturn");
|
||||
car.setModel("Imprezza");
|
||||
|
||||
final Car ford = new Car();
|
||||
ford.setName("Ford");
|
||||
ford.setModel("Focus");
|
||||
|
||||
final GirlFriend permanent = new GirlFriend();
|
||||
permanent.setName("permanent");
|
||||
permanent.setType("permanent");
|
||||
permanent.setCars(Arrays.asList(saturn, subaru));
|
||||
|
||||
final GirlFriend temp = new GirlFriend();
|
||||
temp.setName("temp");
|
||||
temp.setType("temp");
|
||||
temp.setCars(Arrays.asList(car, ford));
|
||||
|
||||
person1.setGirlFriends(Arrays.asList(permanent, temp));
|
||||
|
||||
final IndexQuery indexQuery1 = new IndexQuery();
|
||||
indexQuery1.setId(person1.getId());
|
||||
indexQuery1.setObject(person1);
|
||||
|
||||
final PersonMultipleLevelNested person2 = new PersonMultipleLevelNested();
|
||||
|
||||
person2.setId("2");
|
||||
person2.setName("name");
|
||||
|
||||
person2.setGirlFriends(Arrays.asList(permanent));
|
||||
|
||||
final IndexQuery indexQuery2 = new IndexQuery();
|
||||
indexQuery2.setId(person2.getId());
|
||||
indexQuery2.setObject(person2);
|
||||
|
||||
final List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
indexQueries.add(indexQuery1);
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
return indexQueries;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSearchBooksForPersonInitialLevelNestedType() {
|
||||
|
||||
final List<Car> cars = new ArrayList<>();
|
||||
|
||||
final Car saturn = new Car();
|
||||
saturn.setName("Saturn");
|
||||
saturn.setModel("SL");
|
||||
|
||||
final Car subaru = new Car();
|
||||
subaru.setName("Subaru");
|
||||
subaru.setModel("Imprezza");
|
||||
|
||||
final Car ford = new Car();
|
||||
ford.setName("Ford");
|
||||
ford.setModel("Focus");
|
||||
|
||||
cars.add(saturn);
|
||||
cars.add(subaru);
|
||||
cars.add(ford);
|
||||
|
||||
final Book java = new Book();
|
||||
java.setId("1");
|
||||
java.setName("java");
|
||||
final Author javaAuthor = new Author();
|
||||
javaAuthor.setId("1");
|
||||
javaAuthor.setName("javaAuthor");
|
||||
java.setAuthor(javaAuthor);
|
||||
|
||||
final Book spring = new Book();
|
||||
spring.setId("2");
|
||||
spring.setName("spring");
|
||||
final Author springAuthor = new Author();
|
||||
springAuthor.setId("2");
|
||||
springAuthor.setName("springAuthor");
|
||||
spring.setAuthor(springAuthor);
|
||||
|
||||
final Person foo = new Person();
|
||||
foo.setName("Foo");
|
||||
foo.setId("1");
|
||||
foo.setCar(cars);
|
||||
foo.setBooks(Arrays.asList(java, spring));
|
||||
|
||||
final Car car = new Car();
|
||||
car.setName("Saturn");
|
||||
car.setModel("Imprezza");
|
||||
|
||||
final Person bar = new Person();
|
||||
bar.setId("2");
|
||||
bar.setName("Bar");
|
||||
bar.setCar(Arrays.asList(car));
|
||||
|
||||
final List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
final IndexQuery indexQuery1 = new IndexQuery();
|
||||
indexQuery1.setId(foo.getId());
|
||||
indexQuery1.setObject(foo);
|
||||
|
||||
final IndexQuery indexQuery2 = new IndexQuery();
|
||||
indexQuery2.setId(bar.getId());
|
||||
indexQuery2.setObject(bar);
|
||||
|
||||
indexQueries.add(indexQuery1);
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
elasticsearchTemplate.putMapping(Person.class);
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(Person.class);
|
||||
|
||||
final QueryBuilder builder = nestedQuery("books", boolQuery().must(termQuery("books.name", "java")), ScoreMode.None);
|
||||
|
||||
final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
|
||||
final List<Person> persons = elasticsearchTemplate.queryForList(searchQuery, Person.class);
|
||||
|
||||
assertThat(persons.size(), is(1));
|
||||
}
|
||||
|
||||
/*
|
||||
DATAES-73
|
||||
*/
|
||||
@Test
|
||||
public void shouldIndexAndSearchMapAsNestedType() {
|
||||
//given
|
||||
final Book book1 = new Book();
|
||||
final Book book2 = new Book();
|
||||
|
||||
book1.setId(randomNumeric(5));
|
||||
book1.setName("testBook1");
|
||||
|
||||
book2.setId(randomNumeric(5));
|
||||
book2.setName("testBook2");
|
||||
|
||||
final Map<Integer, Collection<String>> map1 = new HashMap<>();
|
||||
map1.put(1, Arrays.asList("test1", "test2"));
|
||||
|
||||
final Map<Integer, Collection<String>> map2 = new HashMap<>();
|
||||
map2.put(1, Arrays.asList("test3", "test4"));
|
||||
|
||||
book1.setBuckets(map1);
|
||||
book2.setBuckets(map2);
|
||||
|
||||
final List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
final IndexQuery indexQuery1 = new IndexQuery();
|
||||
indexQuery1.setId(book1.getId());
|
||||
indexQuery1.setObject(book1);
|
||||
|
||||
final IndexQuery indexQuery2 = new IndexQuery();
|
||||
indexQuery2.setId(book2.getId());
|
||||
indexQuery2.setObject(book2);
|
||||
|
||||
indexQueries.add(indexQuery1);
|
||||
indexQueries.add(indexQuery2);
|
||||
//when
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(Book.class);
|
||||
//then
|
||||
final SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(nestedQuery("buckets", termQuery("buckets.1", "test3"),ScoreMode.None))
|
||||
.build();
|
||||
final Page<Book> books = elasticsearchTemplate.queryForPage(searchQuery, Book.class);
|
||||
|
||||
assertThat(books.getContent().size(), is(1));
|
||||
assertThat(books.getContent().get(0).getId(), is(book2.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright 2013-2017 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
|
||||
*
|
||||
* http://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;
|
||||
|
||||
import static org.apache.commons.lang.RandomStringUtils.*;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.core.query.GetQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||
import org.springframework.data.elasticsearch.entities.Author;
|
||||
import org.springframework.data.elasticsearch.entities.Book;
|
||||
import org.springframework.data.elasticsearch.entities.Car;
|
||||
import org.springframework.data.elasticsearch.entities.GirlFriend;
|
||||
import org.springframework.data.elasticsearch.entities.Person;
|
||||
import org.springframework.data.elasticsearch.entities.PersonMultipleLevelNested;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/repository-test-nested-object.xml")
|
||||
public class NestedObjectTests {
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
elasticsearchTemplate.deleteIndex(Book.class);
|
||||
elasticsearchTemplate.createIndex(Book.class);
|
||||
elasticsearchTemplate.putMapping(Book.class);
|
||||
elasticsearchTemplate.refresh(Book.class);
|
||||
elasticsearchTemplate.deleteIndex(Person.class);
|
||||
elasticsearchTemplate.createIndex(Person.class);
|
||||
elasticsearchTemplate.putMapping(Person.class);
|
||||
elasticsearchTemplate.refresh(Person.class);
|
||||
elasticsearchTemplate.deleteIndex(PersonMultipleLevelNested.class);
|
||||
elasticsearchTemplate.createIndex(PersonMultipleLevelNested.class);
|
||||
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
||||
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldIndexInitialLevelNestedObject() {
|
||||
|
||||
final List<Car> cars = new ArrayList<>();
|
||||
|
||||
final Car saturn = new Car();
|
||||
saturn.setName("Saturn");
|
||||
saturn.setModel("SL");
|
||||
|
||||
final Car subaru = new Car();
|
||||
subaru.setName("Subaru");
|
||||
subaru.setModel("Imprezza");
|
||||
|
||||
final Car ford = new Car();
|
||||
ford.setName("Ford");
|
||||
ford.setModel("Focus");
|
||||
|
||||
cars.add(saturn);
|
||||
cars.add(subaru);
|
||||
cars.add(ford);
|
||||
|
||||
final Person foo = new Person();
|
||||
foo.setName("Foo");
|
||||
foo.setId("1");
|
||||
foo.setCar(cars);
|
||||
|
||||
final Car car = new Car();
|
||||
car.setName("Saturn");
|
||||
car.setModel("Imprezza");
|
||||
|
||||
final Person bar = new Person();
|
||||
bar.setId("2");
|
||||
bar.setName("Bar");
|
||||
bar.setCar(Arrays.asList(car));
|
||||
|
||||
final List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
final IndexQuery indexQuery1 = new IndexQuery();
|
||||
indexQuery1.setId(foo.getId());
|
||||
indexQuery1.setObject(foo);
|
||||
|
||||
final IndexQuery indexQuery2 = new IndexQuery();
|
||||
indexQuery2.setId(bar.getId());
|
||||
indexQuery2.setObject(bar);
|
||||
|
||||
indexQueries.add(indexQuery1);
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
elasticsearchTemplate.putMapping(Person.class);
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(Person.class);
|
||||
|
||||
final QueryBuilder builder = nestedQuery("car", boolQuery().must(termQuery("car.name", "saturn")).must(termQuery("car.model", "imprezza")), ScoreMode.None);
|
||||
|
||||
final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
|
||||
final List<Person> persons = elasticsearchTemplate.queryForList(searchQuery, Person.class);
|
||||
|
||||
assertThat(persons.size(), is(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldIndexMultipleLevelNestedObject() {
|
||||
//given
|
||||
final List<IndexQuery> indexQueries = createPerson();
|
||||
|
||||
//when
|
||||
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
||||
|
||||
//then
|
||||
final GetQuery getQuery = new GetQuery();
|
||||
getQuery.setId("1");
|
||||
final PersonMultipleLevelNested personIndexed = elasticsearchTemplate.queryForObject(getQuery, PersonMultipleLevelNested.class);
|
||||
assertThat(personIndexed, is(notNullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldIndexMultipleLevelNestedObjectWithIncludeInParent() {
|
||||
//given
|
||||
final List<IndexQuery> indexQueries = createPerson();
|
||||
|
||||
//when
|
||||
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
// then
|
||||
|
||||
final Map mapping = elasticsearchTemplate.getMapping(PersonMultipleLevelNested.class);
|
||||
|
||||
assertThat(mapping, is(notNullValue()));
|
||||
final Map propertyMap = (Map) mapping.get("properties");
|
||||
assertThat(propertyMap, is(notNullValue()));
|
||||
final Map bestCarsAttributes = (Map) propertyMap.get("bestCars");
|
||||
assertThat(bestCarsAttributes.get("include_in_parent"), is(notNullValue()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldSearchUsingNestedQueryOnMultipleLevelNestedObject() {
|
||||
//given
|
||||
final List<IndexQuery> indexQueries = createPerson();
|
||||
|
||||
//when
|
||||
elasticsearchTemplate.putMapping(PersonMultipleLevelNested.class);
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(PersonMultipleLevelNested.class);
|
||||
|
||||
//then
|
||||
final BoolQueryBuilder builder = boolQuery();
|
||||
builder.must(nestedQuery("girlFriends", termQuery("girlFriends.type", "temp"),ScoreMode.None))
|
||||
.must(nestedQuery("girlFriends.cars", termQuery("girlFriends.cars.name", "Ford".toLowerCase()),ScoreMode.None));
|
||||
|
||||
final SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(builder)
|
||||
.build();
|
||||
|
||||
final Page<PersonMultipleLevelNested> personIndexed = elasticsearchTemplate.queryForPage(searchQuery, PersonMultipleLevelNested.class);
|
||||
assertThat(personIndexed, is(notNullValue()));
|
||||
assertThat(personIndexed.getTotalElements(), is(1L));
|
||||
assertThat(personIndexed.getContent().get(0).getId(), is("1"));
|
||||
}
|
||||
|
||||
|
||||
private List<IndexQuery> createPerson() {
|
||||
|
||||
final PersonMultipleLevelNested person1 = new PersonMultipleLevelNested();
|
||||
|
||||
person1.setId("1");
|
||||
person1.setName("name");
|
||||
|
||||
final Car saturn = new Car();
|
||||
saturn.setName("Saturn");
|
||||
saturn.setModel("SL");
|
||||
|
||||
final Car subaru = new Car();
|
||||
subaru.setName("Subaru");
|
||||
subaru.setModel("Imprezza");
|
||||
|
||||
final Car car = new Car();
|
||||
car.setName("Saturn");
|
||||
car.setModel("Imprezza");
|
||||
|
||||
final Car ford = new Car();
|
||||
ford.setName("Ford");
|
||||
ford.setModel("Focus");
|
||||
|
||||
final GirlFriend permanent = new GirlFriend();
|
||||
permanent.setName("permanent");
|
||||
permanent.setType("permanent");
|
||||
permanent.setCars(Arrays.asList(saturn, subaru));
|
||||
|
||||
final GirlFriend temp = new GirlFriend();
|
||||
temp.setName("temp");
|
||||
temp.setType("temp");
|
||||
temp.setCars(Arrays.asList(car, ford));
|
||||
|
||||
person1.setGirlFriends(Arrays.asList(permanent, temp));
|
||||
|
||||
final IndexQuery indexQuery1 = new IndexQuery();
|
||||
indexQuery1.setId(person1.getId());
|
||||
indexQuery1.setObject(person1);
|
||||
|
||||
final PersonMultipleLevelNested person2 = new PersonMultipleLevelNested();
|
||||
|
||||
person2.setId("2");
|
||||
person2.setName("name");
|
||||
|
||||
person2.setGirlFriends(Arrays.asList(permanent));
|
||||
|
||||
final IndexQuery indexQuery2 = new IndexQuery();
|
||||
indexQuery2.setId(person2.getId());
|
||||
indexQuery2.setObject(person2);
|
||||
|
||||
final List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
indexQueries.add(indexQuery1);
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
return indexQueries;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSearchBooksForPersonInitialLevelNestedType() {
|
||||
|
||||
final List<Car> cars = new ArrayList<>();
|
||||
|
||||
final Car saturn = new Car();
|
||||
saturn.setName("Saturn");
|
||||
saturn.setModel("SL");
|
||||
|
||||
final Car subaru = new Car();
|
||||
subaru.setName("Subaru");
|
||||
subaru.setModel("Imprezza");
|
||||
|
||||
final Car ford = new Car();
|
||||
ford.setName("Ford");
|
||||
ford.setModel("Focus");
|
||||
|
||||
cars.add(saturn);
|
||||
cars.add(subaru);
|
||||
cars.add(ford);
|
||||
|
||||
final Book java = new Book();
|
||||
java.setId("1");
|
||||
java.setName("java");
|
||||
final Author javaAuthor = new Author();
|
||||
javaAuthor.setId("1");
|
||||
javaAuthor.setName("javaAuthor");
|
||||
java.setAuthor(javaAuthor);
|
||||
|
||||
final Book spring = new Book();
|
||||
spring.setId("2");
|
||||
spring.setName("spring");
|
||||
final Author springAuthor = new Author();
|
||||
springAuthor.setId("2");
|
||||
springAuthor.setName("springAuthor");
|
||||
spring.setAuthor(springAuthor);
|
||||
|
||||
final Person foo = new Person();
|
||||
foo.setName("Foo");
|
||||
foo.setId("1");
|
||||
foo.setCar(cars);
|
||||
foo.setBooks(Arrays.asList(java, spring));
|
||||
|
||||
final Car car = new Car();
|
||||
car.setName("Saturn");
|
||||
car.setModel("Imprezza");
|
||||
|
||||
final Person bar = new Person();
|
||||
bar.setId("2");
|
||||
bar.setName("Bar");
|
||||
bar.setCar(Arrays.asList(car));
|
||||
|
||||
final List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
final IndexQuery indexQuery1 = new IndexQuery();
|
||||
indexQuery1.setId(foo.getId());
|
||||
indexQuery1.setObject(foo);
|
||||
|
||||
final IndexQuery indexQuery2 = new IndexQuery();
|
||||
indexQuery2.setId(bar.getId());
|
||||
indexQuery2.setObject(bar);
|
||||
|
||||
indexQueries.add(indexQuery1);
|
||||
indexQueries.add(indexQuery2);
|
||||
|
||||
elasticsearchTemplate.putMapping(Person.class);
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(Person.class);
|
||||
|
||||
final QueryBuilder builder = nestedQuery("books", boolQuery().must(termQuery("books.name", "java")), ScoreMode.None);
|
||||
|
||||
final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build();
|
||||
final List<Person> persons = elasticsearchTemplate.queryForList(searchQuery, Person.class);
|
||||
|
||||
assertThat(persons.size(), is(1));
|
||||
}
|
||||
|
||||
/*
|
||||
DATAES-73
|
||||
*/
|
||||
@Test
|
||||
public void shouldIndexAndSearchMapAsNestedType() {
|
||||
//given
|
||||
final Book book1 = new Book();
|
||||
final Book book2 = new Book();
|
||||
|
||||
book1.setId(randomNumeric(5));
|
||||
book1.setName("testBook1");
|
||||
|
||||
book2.setId(randomNumeric(5));
|
||||
book2.setName("testBook2");
|
||||
|
||||
final Map<Integer, Collection<String>> map1 = new HashMap<>();
|
||||
map1.put(1, Arrays.asList("test1", "test2"));
|
||||
|
||||
final Map<Integer, Collection<String>> map2 = new HashMap<>();
|
||||
map2.put(1, Arrays.asList("test3", "test4"));
|
||||
|
||||
book1.setBuckets(map1);
|
||||
book2.setBuckets(map2);
|
||||
|
||||
final List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
final IndexQuery indexQuery1 = new IndexQuery();
|
||||
indexQuery1.setId(book1.getId());
|
||||
indexQuery1.setObject(book1);
|
||||
|
||||
final IndexQuery indexQuery2 = new IndexQuery();
|
||||
indexQuery2.setId(book2.getId());
|
||||
indexQuery2.setObject(book2);
|
||||
|
||||
indexQueries.add(indexQuery1);
|
||||
indexQueries.add(indexQuery2);
|
||||
//when
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(Book.class);
|
||||
//then
|
||||
final SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(nestedQuery("buckets", termQuery("buckets.1", "test3"),ScoreMode.None))
|
||||
.build();
|
||||
final Page<Book> books = elasticsearchTemplate.queryForPage(searchQuery, Book.class);
|
||||
|
||||
assertThat(books.getContent().size(), is(1));
|
||||
assertThat(books.getContent().get(0).getId(), is(book2.getId()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +1,35 @@
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.elasticsearch.repositories.nondocument.NonDocumentEntityRepository;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class NonDocumentEntityTests {
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void shouldNotInitialiseRepositoryWithNonDocument() {
|
||||
// when
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/repository-non-document-entity.xml");
|
||||
ctx.getBean(NonDocumentEntityRepository.class);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.data.elasticsearch.repositories.nondocument.NonDocumentEntityRepository;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class NonDocumentEntityTests {
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
public void shouldNotInitialiseRepositoryWithNonDocument() {
|
||||
// when
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/repository-non-document-entity.xml");
|
||||
ctx.getBean(NonDocumentEntityRepository.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.config;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.elasticsearch.client.TransportClientFactoryBean;
|
||||
import org.springframework.data.elasticsearch.repositories.sample.SampleElasticsearchRepository;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("namespace.xml")
|
||||
public class ElasticsearchNamespaceHandlerTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void shouldCreateTransportClient() {
|
||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(notNullValue()));
|
||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(instanceOf(TransportClientFactoryBean.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateRepository() {
|
||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(notNullValue()));
|
||||
assertThat(context.getBean(SampleElasticsearchRepository.class),
|
||||
is(instanceOf(SampleElasticsearchRepository.class)));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.config;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.elasticsearch.client.TransportClientFactoryBean;
|
||||
import org.springframework.data.elasticsearch.repositories.sample.SampleElasticsearchRepository;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("namespace.xml")
|
||||
public class ElasticsearchNamespaceHandlerTests {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void shouldCreateTransportClient() {
|
||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(notNullValue()));
|
||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(instanceOf(TransportClientFactoryBean.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateRepository() {
|
||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(notNullValue()));
|
||||
assertThat(context.getBean(SampleElasticsearchRepository.class),
|
||||
is(instanceOf(SampleElasticsearchRepository.class)));
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,73 +1,73 @@
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.convert;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class DateTimeConvertersTests {
|
||||
|
||||
@Test
|
||||
public void testJodaDateTimeConverterWithNullValue() {
|
||||
Assert.assertNull(DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJodaDateTimeConverter() {
|
||||
DateTime dateTime = new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC);
|
||||
Assert
|
||||
.assertEquals("2013-01-24T06:35:00.000Z", DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(dateTime));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJodaLocalDateTimeConverterWithNullValue() {
|
||||
Assert.assertNull(DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJodaLocalDateTimeConverter() {
|
||||
LocalDateTime dateTime = new LocalDateTime(new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC).getMillis(),
|
||||
DateTimeZone.UTC);
|
||||
Assert.assertEquals("2013-01-24T06:35:00.000Z",
|
||||
DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(dateTime));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaDateConverterWithNullValue() {
|
||||
Assert.assertNull(DateTimeConverters.JavaDateConverter.INSTANCE.convert(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaDateConverter() {
|
||||
DateTime dateTime = new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
calendar.setTimeInMillis(dateTime.getMillis());
|
||||
|
||||
Assert.assertEquals("2013-01-24T06:35:00.000Z",
|
||||
DateTimeConverters.JavaDateConverter.INSTANCE.convert(calendar.getTime()));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.convert;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class DateTimeConvertersTests {
|
||||
|
||||
@Test
|
||||
public void testJodaDateTimeConverterWithNullValue() {
|
||||
Assert.assertNull(DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJodaDateTimeConverter() {
|
||||
DateTime dateTime = new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC);
|
||||
Assert
|
||||
.assertEquals("2013-01-24T06:35:00.000Z", DateTimeConverters.JodaDateTimeConverter.INSTANCE.convert(dateTime));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJodaLocalDateTimeConverterWithNullValue() {
|
||||
Assert.assertNull(DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJodaLocalDateTimeConverter() {
|
||||
LocalDateTime dateTime = new LocalDateTime(new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC).getMillis(),
|
||||
DateTimeZone.UTC);
|
||||
Assert.assertEquals("2013-01-24T06:35:00.000Z",
|
||||
DateTimeConverters.JodaLocalDateTimeConverter.INSTANCE.convert(dateTime));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaDateConverterWithNullValue() {
|
||||
Assert.assertNull(DateTimeConverters.JavaDateConverter.INSTANCE.convert(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJavaDateConverter() {
|
||||
DateTime dateTime = new DateTime(2013, 1, 24, 6, 35, 0, DateTimeZone.UTC);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
calendar.setTimeInMillis(dateTime.getMillis());
|
||||
|
||||
Assert.assertEquals("2013-01-24T06:35:00.000Z",
|
||||
DateTimeConverters.JavaDateConverter.INSTANCE.convert(calendar.getTime()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +1,57 @@
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.convert;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class MappingElasticsearchConverterTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldFailToInitializeGivenMappingContextIsNull() {
|
||||
// given
|
||||
new MappingElasticsearchConverter(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnMappingContextWithWhichItWasInitialized() {
|
||||
// given
|
||||
MappingContext mappingContext = new SimpleElasticsearchMappingContext();
|
||||
MappingElasticsearchConverter converter = new MappingElasticsearchConverter(mappingContext);
|
||||
// then
|
||||
assertThat(converter.getMappingContext(), is(notNullValue()));
|
||||
assertThat(converter.getMappingContext(), is(sameInstance(mappingContext)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnDefaultConversionService() {
|
||||
// given
|
||||
MappingElasticsearchConverter converter = new MappingElasticsearchConverter(new SimpleElasticsearchMappingContext());
|
||||
// when
|
||||
ConversionService conversionService = converter.getConversionService();
|
||||
// then
|
||||
assertThat(conversionService, is(notNullValue()));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.convert;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class MappingElasticsearchConverterTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldFailToInitializeGivenMappingContextIsNull() {
|
||||
// given
|
||||
new MappingElasticsearchConverter(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnMappingContextWithWhichItWasInitialized() {
|
||||
// given
|
||||
MappingContext mappingContext = new SimpleElasticsearchMappingContext();
|
||||
MappingElasticsearchConverter converter = new MappingElasticsearchConverter(mappingContext);
|
||||
// then
|
||||
assertThat(converter.getMappingContext(), is(notNullValue()));
|
||||
assertThat(converter.getMappingContext(), is(sameInstance(mappingContext)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnDefaultConversionService() {
|
||||
// given
|
||||
MappingElasticsearchConverter converter = new MappingElasticsearchConverter(new SimpleElasticsearchMappingContext());
|
||||
// when
|
||||
ConversionService conversionService = converter.getConversionService();
|
||||
// then
|
||||
assertThat(conversionService, is(notNullValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,111 +1,111 @@
|
||||
/*
|
||||
* Copyright 2014-2017 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
|
||||
*
|
||||
* http://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.facet;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.Integer;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.text;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
|
||||
/**
|
||||
* Simple type to test facets
|
||||
*
|
||||
* @author Artur Konczak
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Document(indexName = "test-index-articles", type = "article", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class ArticleEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String title;
|
||||
@Field(type = text, fielddata = true)
|
||||
private String subject;
|
||||
|
||||
@MultiField(
|
||||
mainField = @Field(type = text),
|
||||
otherFields = {
|
||||
@InnerField(suffix = "untouched", type = text, store = true, fielddata = true, indexAnalyzer = "keyword"),
|
||||
@InnerField(suffix = "sort", type = text, store = true, indexAnalyzer = "keyword")
|
||||
}
|
||||
)
|
||||
private List<String> authors = new ArrayList<>();
|
||||
|
||||
@Field(type = Integer, store = true)
|
||||
private List<Integer> publishedYears = new ArrayList<>();
|
||||
|
||||
private int score;
|
||||
|
||||
private ArticleEntity() {
|
||||
|
||||
}
|
||||
|
||||
public ArticleEntity(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public List<String> getAuthors() {
|
||||
return authors;
|
||||
}
|
||||
|
||||
public void setAuthors(List<String> authors) {
|
||||
this.authors = authors;
|
||||
}
|
||||
|
||||
public List<Integer> getPublishedYears() {
|
||||
return publishedYears;
|
||||
}
|
||||
|
||||
public void setPublishedYears(List<Integer> publishedYears) {
|
||||
this.publishedYears = publishedYears;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(int score) {
|
||||
this.score = score;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2014-2017 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
|
||||
*
|
||||
* http://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.facet;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.Integer;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.text;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
|
||||
/**
|
||||
* Simple type to test facets
|
||||
*
|
||||
* @author Artur Konczak
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Document(indexName = "test-index-articles", type = "article", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class ArticleEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String title;
|
||||
@Field(type = text, fielddata = true)
|
||||
private String subject;
|
||||
|
||||
@MultiField(
|
||||
mainField = @Field(type = text),
|
||||
otherFields = {
|
||||
@InnerField(suffix = "untouched", type = text, store = true, fielddata = true, indexAnalyzer = "keyword"),
|
||||
@InnerField(suffix = "sort", type = text, store = true, indexAnalyzer = "keyword")
|
||||
}
|
||||
)
|
||||
private List<String> authors = new ArrayList<>();
|
||||
|
||||
@Field(type = Integer, store = true)
|
||||
private List<Integer> publishedYears = new ArrayList<>();
|
||||
|
||||
private int score;
|
||||
|
||||
private ArticleEntity() {
|
||||
|
||||
}
|
||||
|
||||
public ArticleEntity(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return subject;
|
||||
}
|
||||
|
||||
public void setSubject(String subject) {
|
||||
this.subject = subject;
|
||||
}
|
||||
|
||||
public List<String> getAuthors() {
|
||||
return authors;
|
||||
}
|
||||
|
||||
public void setAuthors(List<String> authors) {
|
||||
this.authors = authors;
|
||||
}
|
||||
|
||||
public List<Integer> getPublishedYears() {
|
||||
return publishedYears;
|
||||
}
|
||||
|
||||
public void setPublishedYears(List<Integer> publishedYears) {
|
||||
this.publishedYears = publishedYears;
|
||||
}
|
||||
|
||||
public int getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(int score) {
|
||||
this.score = score;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
/*
|
||||
* Copyright 2014 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
|
||||
*
|
||||
* http://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.facet;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
|
||||
/**
|
||||
* Simple type to test facets
|
||||
*
|
||||
* @author Artur Konczak
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class ArticleEntityBuilder {
|
||||
|
||||
private ArticleEntity result;
|
||||
|
||||
public ArticleEntityBuilder(String id) {
|
||||
result = new ArticleEntity(id);
|
||||
}
|
||||
|
||||
public ArticleEntityBuilder title(String title) {
|
||||
result.setTitle(title);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArticleEntityBuilder subject(String subject) {
|
||||
result.setSubject(subject);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArticleEntityBuilder addAuthor(String author) {
|
||||
result.getAuthors().add(author);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArticleEntityBuilder addPublishedYear(Integer year) {
|
||||
result.getPublishedYears().add(year);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArticleEntityBuilder score(int score) {
|
||||
result.setScore(score);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArticleEntity build() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public IndexQuery buildIndex() {
|
||||
IndexQuery indexQuery = new IndexQuery();
|
||||
indexQuery.setId(result.getId());
|
||||
indexQuery.setObject(result);
|
||||
return indexQuery;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2014 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
|
||||
*
|
||||
* http://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.facet;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
|
||||
/**
|
||||
* Simple type to test facets
|
||||
*
|
||||
* @author Artur Konczak
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class ArticleEntityBuilder {
|
||||
|
||||
private ArticleEntity result;
|
||||
|
||||
public ArticleEntityBuilder(String id) {
|
||||
result = new ArticleEntity(id);
|
||||
}
|
||||
|
||||
public ArticleEntityBuilder title(String title) {
|
||||
result.setTitle(title);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArticleEntityBuilder subject(String subject) {
|
||||
result.setSubject(subject);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArticleEntityBuilder addAuthor(String author) {
|
||||
result.getAuthors().add(author);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArticleEntityBuilder addPublishedYear(Integer year) {
|
||||
result.getPublishedYears().add(year);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArticleEntityBuilder score(int score) {
|
||||
result.setScore(score);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ArticleEntity build() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public IndexQuery buildIndex() {
|
||||
IndexQuery indexQuery = new IndexQuery();
|
||||
indexQuery.setId(result.getId());
|
||||
indexQuery.setObject(result);
|
||||
return indexQuery;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,109 +1,109 @@
|
||||
/*
|
||||
* Copyright 2013-2017 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
|
||||
*
|
||||
* http://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.mapping;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.model.Property;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class SimpleElasticsearchPersistentEntityTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionGivenVersionPropertyIsNotLong() throws NoSuchFieldException, IntrospectionException {
|
||||
// given
|
||||
TypeInformation typeInformation = ClassTypeInformation.from(EntityWithWrongVersionType.class);
|
||||
SimpleElasticsearchPersistentEntity<EntityWithWrongVersionType> entity = new SimpleElasticsearchPersistentEntity<>(
|
||||
typeInformation);
|
||||
|
||||
SimpleElasticsearchPersistentProperty persistentProperty = createProperty(entity, "version");
|
||||
|
||||
// when
|
||||
entity.addPersistentProperty(persistentProperty);
|
||||
}
|
||||
|
||||
@Test(expected = MappingException.class)
|
||||
public void shouldThrowExceptionGivenMultipleVersionPropertiesArePresent()
|
||||
throws NoSuchFieldException, IntrospectionException {
|
||||
// given
|
||||
TypeInformation typeInformation = ClassTypeInformation.from(EntityWithMultipleVersionField.class);
|
||||
SimpleElasticsearchPersistentEntity<EntityWithMultipleVersionField> entity = new SimpleElasticsearchPersistentEntity<>(
|
||||
typeInformation);
|
||||
|
||||
SimpleElasticsearchPersistentProperty persistentProperty1 = createProperty(entity, "version1");
|
||||
|
||||
SimpleElasticsearchPersistentProperty persistentProperty2 = createProperty(entity, "version2");
|
||||
|
||||
entity.addPersistentProperty(persistentProperty1);
|
||||
// when
|
||||
entity.addPersistentProperty(persistentProperty2);
|
||||
}
|
||||
|
||||
private static SimpleElasticsearchPersistentProperty createProperty(SimpleElasticsearchPersistentEntity<?> entity,
|
||||
String field) {
|
||||
|
||||
TypeInformation<?> type = entity.getTypeInformation();
|
||||
Property property = Property.of(type, ReflectionUtils.findField(entity.getType(), field));
|
||||
return new SimpleElasticsearchPersistentProperty(property, entity, SimpleTypeHolder.DEFAULT);
|
||||
|
||||
}
|
||||
|
||||
private class EntityWithWrongVersionType {
|
||||
|
||||
@Version private String version;
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
|
||||
private class EntityWithMultipleVersionField {
|
||||
|
||||
@Version private Long version1;
|
||||
@Version private Long version2;
|
||||
|
||||
public Long getVersion1() {
|
||||
return version1;
|
||||
}
|
||||
|
||||
public void setVersion1(Long version1) {
|
||||
this.version1 = version1;
|
||||
}
|
||||
|
||||
public Long getVersion2() {
|
||||
return version2;
|
||||
}
|
||||
|
||||
public void setVersion2(Long version2) {
|
||||
this.version2 = version2;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2013-2017 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
|
||||
*
|
||||
* http://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.mapping;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.mapping.MappingException;
|
||||
import org.springframework.data.mapping.model.Property;
|
||||
import org.springframework.data.mapping.model.SimpleTypeHolder;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class SimpleElasticsearchPersistentEntityTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionGivenVersionPropertyIsNotLong() throws NoSuchFieldException, IntrospectionException {
|
||||
// given
|
||||
TypeInformation typeInformation = ClassTypeInformation.from(EntityWithWrongVersionType.class);
|
||||
SimpleElasticsearchPersistentEntity<EntityWithWrongVersionType> entity = new SimpleElasticsearchPersistentEntity<>(
|
||||
typeInformation);
|
||||
|
||||
SimpleElasticsearchPersistentProperty persistentProperty = createProperty(entity, "version");
|
||||
|
||||
// when
|
||||
entity.addPersistentProperty(persistentProperty);
|
||||
}
|
||||
|
||||
@Test(expected = MappingException.class)
|
||||
public void shouldThrowExceptionGivenMultipleVersionPropertiesArePresent()
|
||||
throws NoSuchFieldException, IntrospectionException {
|
||||
// given
|
||||
TypeInformation typeInformation = ClassTypeInformation.from(EntityWithMultipleVersionField.class);
|
||||
SimpleElasticsearchPersistentEntity<EntityWithMultipleVersionField> entity = new SimpleElasticsearchPersistentEntity<>(
|
||||
typeInformation);
|
||||
|
||||
SimpleElasticsearchPersistentProperty persistentProperty1 = createProperty(entity, "version1");
|
||||
|
||||
SimpleElasticsearchPersistentProperty persistentProperty2 = createProperty(entity, "version2");
|
||||
|
||||
entity.addPersistentProperty(persistentProperty1);
|
||||
// when
|
||||
entity.addPersistentProperty(persistentProperty2);
|
||||
}
|
||||
|
||||
private static SimpleElasticsearchPersistentProperty createProperty(SimpleElasticsearchPersistentEntity<?> entity,
|
||||
String field) {
|
||||
|
||||
TypeInformation<?> type = entity.getTypeInformation();
|
||||
Property property = Property.of(type, ReflectionUtils.findField(entity.getType(), field));
|
||||
return new SimpleElasticsearchPersistentProperty(property, entity, SimpleTypeHolder.DEFAULT);
|
||||
|
||||
}
|
||||
|
||||
private class EntityWithWrongVersionType {
|
||||
|
||||
@Version private String version;
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
|
||||
private class EntityWithMultipleVersionField {
|
||||
|
||||
@Version private Long version1;
|
||||
@Version private Long version2;
|
||||
|
||||
public Long getVersion1() {
|
||||
return version1;
|
||||
}
|
||||
|
||||
public void setVersion1(Long version1) {
|
||||
this.version1 = version1;
|
||||
}
|
||||
|
||||
public Long getVersion2() {
|
||||
return version2;
|
||||
}
|
||||
|
||||
public void setVersion2(Long version2) {
|
||||
this.version2 = version2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,42 +1,42 @@
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class Author {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class Author {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
/*
|
||||
* Copyright 2013-2017 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Document(indexName = "test-index-book", type = "book", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class Book {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
@Field(type = FieldType.Object)
|
||||
private Author author;
|
||||
@Field(type = FieldType.Nested)
|
||||
private Map<Integer, Collection<String>> buckets = new HashMap<>();
|
||||
}
|
||||
/*
|
||||
* Copyright 2013-2017 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Document(indexName = "test-index-book", type = "book", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class Book {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
@Field(type = FieldType.Object)
|
||||
private Author author;
|
||||
@Field(type = FieldType.Nested)
|
||||
private Map<Integer, Collection<String>> buckets = new HashMap<>();
|
||||
}
|
||||
|
||||
@@ -1,59 +1,59 @@
|
||||
/*
|
||||
* Copyright 2014 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
|
||||
public class GirlFriend {
|
||||
|
||||
private String name;
|
||||
|
||||
private String type;
|
||||
|
||||
@Field(type = FieldType.Nested)
|
||||
private List<Car> cars;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public List<Car> getCars() {
|
||||
return cars;
|
||||
}
|
||||
|
||||
public void setCars(List<Car> cars) {
|
||||
this.cars = cars;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2014 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
|
||||
public class GirlFriend {
|
||||
|
||||
private String name;
|
||||
|
||||
private String type;
|
||||
|
||||
@Field(type = FieldType.Nested)
|
||||
private List<Car> cars;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public List<Car> getCars() {
|
||||
return cars;
|
||||
}
|
||||
|
||||
public void setCars(List<Car> cars) {
|
||||
this.cars = cars;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class NonDocumentEntity {
|
||||
|
||||
@Id
|
||||
private String someId;
|
||||
private String someField1;
|
||||
private String someField2;
|
||||
|
||||
public String getSomeField1() {
|
||||
return someField1;
|
||||
}
|
||||
|
||||
public void setSomeField1(String someField1) {
|
||||
this.someField1 = someField1;
|
||||
}
|
||||
|
||||
public String getSomeField2() {
|
||||
return someField2;
|
||||
}
|
||||
|
||||
public void setSomeField2(String someField2) {
|
||||
this.someField2 = someField2;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class NonDocumentEntity {
|
||||
|
||||
@Id
|
||||
private String someId;
|
||||
private String someField1;
|
||||
private String someField2;
|
||||
|
||||
public String getSomeField1() {
|
||||
return someField1;
|
||||
}
|
||||
|
||||
public void setSomeField1(String someField1) {
|
||||
this.someField1 = someField1;
|
||||
}
|
||||
|
||||
public String getSomeField2() {
|
||||
return someField2;
|
||||
}
|
||||
|
||||
public void setSomeField2(String someField2) {
|
||||
this.someField2 = someField2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,88 +1,88 @@
|
||||
/*
|
||||
* Copyright 2014 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
|
||||
@Document(indexName = "test-index-person-multiple-level-nested", type = "user", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class PersonMultipleLevelNested {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
@Field(type = FieldType.Nested)
|
||||
private List<GirlFriend> girlFriends;
|
||||
|
||||
@Field(type = FieldType.Nested)
|
||||
private List<Car> cars;
|
||||
|
||||
@Field(type = FieldType.Nested, includeInParent = true)
|
||||
private List<Car> bestCars;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<GirlFriend> getGirlFriends() {
|
||||
return girlFriends;
|
||||
}
|
||||
|
||||
public void setGirlFriends(List<GirlFriend> girlFriends) {
|
||||
this.girlFriends = girlFriends;
|
||||
}
|
||||
|
||||
public List<Car> getCars() {
|
||||
return cars;
|
||||
}
|
||||
|
||||
public void setCars(List<Car> cars) {
|
||||
this.cars = cars;
|
||||
}
|
||||
|
||||
public List<Car> getBestCars() {
|
||||
return bestCars;
|
||||
}
|
||||
|
||||
public void setBestCars(List<Car> bestCars) {
|
||||
this.bestCars = bestCars;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2014 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
|
||||
@Document(indexName = "test-index-person-multiple-level-nested", type = "user", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class PersonMultipleLevelNested {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private String name;
|
||||
|
||||
@Field(type = FieldType.Nested)
|
||||
private List<GirlFriend> girlFriends;
|
||||
|
||||
@Field(type = FieldType.Nested)
|
||||
private List<Car> cars;
|
||||
|
||||
@Field(type = FieldType.Nested, includeInParent = true)
|
||||
private List<Car> bestCars;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<GirlFriend> getGirlFriends() {
|
||||
return girlFriends;
|
||||
}
|
||||
|
||||
public void setGirlFriends(List<GirlFriend> girlFriends) {
|
||||
this.girlFriends = girlFriends;
|
||||
}
|
||||
|
||||
public List<Car> getCars() {
|
||||
return cars;
|
||||
}
|
||||
|
||||
public void setCars(List<Car> cars) {
|
||||
this.cars = cars;
|
||||
}
|
||||
|
||||
public List<Car> getBestCars() {
|
||||
return bestCars;
|
||||
}
|
||||
|
||||
public void setBestCars(List<Car> bestCars) {
|
||||
this.bestCars = bestCars;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,97 +1,97 @@
|
||||
/*
|
||||
* Copyright 2014 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Document(indexName = "test-index-product", type = "test-product-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class Product {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private List<String> title;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
private String text;
|
||||
|
||||
private List<String> categories;
|
||||
|
||||
private Float weight;
|
||||
|
||||
@Field(type = FieldType.Float)
|
||||
private Float price;
|
||||
|
||||
private Integer popularity;
|
||||
|
||||
private boolean available;
|
||||
|
||||
private String location;
|
||||
|
||||
private Date lastModified;
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Product other = (Product) obj;
|
||||
if (id == null) {
|
||||
if (other.id != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!id.equals(other.id)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2014 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Document(indexName = "test-index-product", type = "test-product-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class Product {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
private List<String> title;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
private String text;
|
||||
|
||||
private List<String> categories;
|
||||
|
||||
private Float weight;
|
||||
|
||||
@Field(type = FieldType.Float)
|
||||
private Float price;
|
||||
|
||||
private Integer popularity;
|
||||
|
||||
private boolean available;
|
||||
|
||||
private String location;
|
||||
|
||||
private Date lastModified;
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
Product other = (Product) obj;
|
||||
if (id == null) {
|
||||
if (other.id != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!id.equals(other.id)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,96 +1,96 @@
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
import java.lang.Double;
|
||||
import java.lang.Long;
|
||||
import java.lang.Object;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Document(indexName = "test-index-sample", type = "test-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SampleEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@Field(type = text, store = true, fielddata = true)
|
||||
private String type;
|
||||
@Field(type = text, store = true, fielddata = true)
|
||||
private String message;
|
||||
private int rate;
|
||||
@ScriptedField
|
||||
private Double scriptedRate;
|
||||
private boolean available;
|
||||
private String highlightedMessage;
|
||||
|
||||
private GeoPoint location;
|
||||
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
SampleEntity that = (SampleEntity) o;
|
||||
|
||||
if (available != that.available) return false;
|
||||
if (rate != that.rate) return false;
|
||||
if (highlightedMessage != null ? !highlightedMessage.equals(that.highlightedMessage) : that.highlightedMessage != null)
|
||||
return false;
|
||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||
if (location != null ? !location.equals(that.location) : that.location != null) return false;
|
||||
if (message != null ? !message.equals(that.message) : that.message != null) return false;
|
||||
if (type != null ? !type.equals(that.type) : that.type != null) return false;
|
||||
if (version != null ? !version.equals(that.version) : that.version != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = id != null ? id.hashCode() : 0;
|
||||
result = 31 * result + (type != null ? type.hashCode() : 0);
|
||||
result = 31 * result + (message != null ? message.hashCode() : 0);
|
||||
result = 31 * result + rate;
|
||||
result = 31 * result + (available ? 1 : 0);
|
||||
result = 31 * result + (highlightedMessage != null ? highlightedMessage.hashCode() : 0);
|
||||
result = 31 * result + (location != null ? location.hashCode() : 0);
|
||||
result = 31 * result + (version != null ? version.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
import java.lang.Double;
|
||||
import java.lang.Long;
|
||||
import java.lang.Object;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Version;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Document(indexName = "test-index-sample", type = "test-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SampleEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@Field(type = text, store = true, fielddata = true)
|
||||
private String type;
|
||||
@Field(type = text, store = true, fielddata = true)
|
||||
private String message;
|
||||
private int rate;
|
||||
@ScriptedField
|
||||
private Double scriptedRate;
|
||||
private boolean available;
|
||||
private String highlightedMessage;
|
||||
|
||||
private GeoPoint location;
|
||||
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
SampleEntity that = (SampleEntity) o;
|
||||
|
||||
if (available != that.available) return false;
|
||||
if (rate != that.rate) return false;
|
||||
if (highlightedMessage != null ? !highlightedMessage.equals(that.highlightedMessage) : that.highlightedMessage != null)
|
||||
return false;
|
||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||
if (location != null ? !location.equals(that.location) : that.location != null) return false;
|
||||
if (message != null ? !message.equals(that.message) : that.message != null) return false;
|
||||
if (type != null ? !type.equals(that.type) : that.type != null) return false;
|
||||
if (version != null ? !version.equals(that.version) : that.version != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = id != null ? id.hashCode() : 0;
|
||||
result = 31 * result + (type != null ? type.hashCode() : 0);
|
||||
result = 31 * result + (message != null ? message.hashCode() : 0);
|
||||
result = 31 * result + rate;
|
||||
result = 31 * result + (available ? 1 : 0);
|
||||
result = 31 * result + (highlightedMessage != null ? highlightedMessage.hashCode() : 0);
|
||||
result = 31 * result + (location != null ? location.hashCode() : 0);
|
||||
result = 31 * result + (version != null ? version.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,68 +1,68 @@
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.text;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Document(indexName = "test-index-sample-mapping", type = "mapping", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SampleMappingEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Field(type = text, index = false, store = true, analyzer = "standard")
|
||||
private String message;
|
||||
|
||||
private NestedEntity nested;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
static class NestedEntity {
|
||||
|
||||
@Field(type = text)
|
||||
private String someField;
|
||||
|
||||
public String getSomeField() {
|
||||
return someField;
|
||||
}
|
||||
|
||||
public void setSomeField(String someField) {
|
||||
this.someField = someField;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.entities;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.text;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Document(indexName = "test-index-sample-mapping", type = "mapping", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SampleMappingEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Field(type = text, index = false, store = true, analyzer = "standard")
|
||||
private String message;
|
||||
|
||||
private NestedEntity nested;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
static class NestedEntity {
|
||||
|
||||
@Field(type = text)
|
||||
private String someField;
|
||||
|
||||
public String getSomeField() {
|
||||
return someField;
|
||||
}
|
||||
|
||||
public void setSomeField(String someField) {
|
||||
this.someField = someField;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,27 +1,27 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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
|
||||
*
|
||||
* http://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.book;
|
||||
|
||||
import org.springframework.data.elasticsearch.entities.Book;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public interface SampleElasticSearchBookRepository extends ElasticsearchRepository<Book, String> {
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2013-2014 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
|
||||
*
|
||||
* http://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.book;
|
||||
|
||||
import org.springframework.data.elasticsearch.entities.Book;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public interface SampleElasticSearchBookRepository extends ElasticsearchRepository<Book, String> {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
/*
|
||||
* Copyright 2014-2017 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
|
||||
*
|
||||
* http://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.cdi;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.elasticsearch.entities.Product;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public interface CdiProductRepository extends CrudRepository<Product, String> {
|
||||
|
||||
Optional<Product> findById(String id);
|
||||
}
|
||||
/*
|
||||
* Copyright 2014-2017 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
|
||||
*
|
||||
* http://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.cdi;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.elasticsearch.entities.Product;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public interface CdiProductRepository extends CrudRepository<Product, String> {
|
||||
|
||||
Optional<Product> findById(String id);
|
||||
}
|
||||
|
||||
@@ -1,58 +1,58 @@
|
||||
/*
|
||||
* Copyright 2014-2016 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
|
||||
*
|
||||
* http://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.cdi;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
class CdiRepositoryClient {
|
||||
|
||||
private CdiProductRepository repository;
|
||||
private SamplePersonRepository samplePersonRepository;
|
||||
private QualifiedProductRepository qualifiedProductRepository;
|
||||
|
||||
public CdiProductRepository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setRepository(CdiProductRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public SamplePersonRepository getSamplePersonRepository() {
|
||||
return samplePersonRepository;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setSamplePersonRepository(SamplePersonRepository samplePersonRepository) {
|
||||
this.samplePersonRepository = samplePersonRepository;
|
||||
}
|
||||
|
||||
public QualifiedProductRepository getQualifiedProductRepository() {
|
||||
return qualifiedProductRepository;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setQualifiedProductRepository(
|
||||
@PersonDB @OtherQualifier QualifiedProductRepository qualifiedProductRepository) {
|
||||
this.qualifiedProductRepository = qualifiedProductRepository;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2014-2016 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
|
||||
*
|
||||
* http://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.cdi;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
class CdiRepositoryClient {
|
||||
|
||||
private CdiProductRepository repository;
|
||||
private SamplePersonRepository samplePersonRepository;
|
||||
private QualifiedProductRepository qualifiedProductRepository;
|
||||
|
||||
public CdiProductRepository getRepository() {
|
||||
return repository;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setRepository(CdiProductRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
public SamplePersonRepository getSamplePersonRepository() {
|
||||
return samplePersonRepository;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setSamplePersonRepository(SamplePersonRepository samplePersonRepository) {
|
||||
this.samplePersonRepository = samplePersonRepository;
|
||||
}
|
||||
|
||||
public QualifiedProductRepository getQualifiedProductRepository() {
|
||||
return qualifiedProductRepository;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setQualifiedProductRepository(
|
||||
@PersonDB @OtherQualifier QualifiedProductRepository qualifiedProductRepository) {
|
||||
this.qualifiedProductRepository = qualifiedProductRepository;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,56 +1,56 @@
|
||||
/*
|
||||
* Copyright 2014-2015 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
|
||||
*
|
||||
* http://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.cdi;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.inject.Produces;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.node.NodeValidationException;
|
||||
import org.springframework.data.elasticsearch.Utils;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@ApplicationScoped
|
||||
class ElasticsearchTemplateProducer {
|
||||
|
||||
@Produces
|
||||
public Client createNodeClient() throws NodeValidationException {
|
||||
return Utils.getNodeClient();
|
||||
}
|
||||
|
||||
@Produces
|
||||
public ElasticsearchOperations createElasticsearchTemplate(Client client) {
|
||||
return new ElasticsearchTemplate(client);
|
||||
}
|
||||
|
||||
@Produces
|
||||
@OtherQualifier
|
||||
@PersonDB
|
||||
public ElasticsearchOperations createQualifiedElasticsearchTemplate(Client client) {
|
||||
return new ElasticsearchTemplate(client);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void shutdown() {
|
||||
// remove everything to avoid conflicts with other tests in case server not shut down properly
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2014-2015 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
|
||||
*
|
||||
* http://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.cdi;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.inject.Produces;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.node.NodeValidationException;
|
||||
import org.springframework.data.elasticsearch.Utils;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@ApplicationScoped
|
||||
class ElasticsearchTemplateProducer {
|
||||
|
||||
@Produces
|
||||
public Client createNodeClient() throws NodeValidationException {
|
||||
return Utils.getNodeClient();
|
||||
}
|
||||
|
||||
@Produces
|
||||
public ElasticsearchOperations createElasticsearchTemplate(Client client) {
|
||||
return new ElasticsearchTemplate(client);
|
||||
}
|
||||
|
||||
@Produces
|
||||
@OtherQualifier
|
||||
@PersonDB
|
||||
public ElasticsearchOperations createQualifiedElasticsearchTemplate(Client client) {
|
||||
return new ElasticsearchTemplate(client);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void shutdown() {
|
||||
// remove everything to avoid conflicts with other tests in case server not shut down properly
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,132 +1,132 @@
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.custom;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.annotations.Query;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoBox;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
import org.springframework.data.geo.Box;
|
||||
import org.springframework.data.geo.Distance;
|
||||
import org.springframework.data.geo.Point;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Kevin Leturc
|
||||
*/
|
||||
public interface SampleCustomMethodRepository extends ElasticsearchRepository<SampleEntity, String> {
|
||||
|
||||
Page<SampleEntity> findByType(String type, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByTypeNot(String type, Pageable pageable);
|
||||
|
||||
@Query("{\"bool\" : {\"must\" : {\"term\" : {\"message\" : \"?0\"}}}}")
|
||||
Page<SampleEntity> findByMessage(String message, Pageable pageable);
|
||||
|
||||
@Query("{\"bool\" : {\"must\" : {\"term\" : {\"message\" : \"?0\"}}}}")
|
||||
List<SampleEntity> findByMessage(String message);
|
||||
|
||||
Page<SampleEntity> findByAvailable(boolean available, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByRateLessThan(int rate, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByRateBefore(int rate, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByRateAfter(int rate, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByMessageLike(String message, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByMessageStartingWith(String message, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByMessageEndingWith(String message, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByMessageContaining(String message, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByIdIn(List<String> ids, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByIdNotIn(List<String> ids, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByAvailableTrue(Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByAvailableFalse(Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByMessageOrderByTypeAsc(String message, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocation(GeoPoint point, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocationAndMessage(GeoPoint point, String msg, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocationWithin(GeoPoint point, String distance, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocationWithin(Point point, Distance distance, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocationNear(GeoBox box, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocationNear(Box box, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocationNear(Point point, Distance distance, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocationNear(GeoPoint point, String distance, Pageable pageable);
|
||||
|
||||
Stream<SampleEntity> findByType(String type);
|
||||
|
||||
long countByType(String type);
|
||||
|
||||
long countByTypeNot(String type);
|
||||
|
||||
long countByAvailable(boolean available);
|
||||
|
||||
long countByRateLessThan(int rate);
|
||||
|
||||
long countByRateBefore(int rate);
|
||||
|
||||
long countByRateAfter(int rate);
|
||||
|
||||
long countByMessageLike(String message);
|
||||
|
||||
long countByMessageStartingWith(String message);
|
||||
|
||||
long countByMessageEndingWith(String message);
|
||||
|
||||
long countByMessageContaining(String message);
|
||||
|
||||
long countByIdIn(List<String> ids);
|
||||
|
||||
long countByIdNotIn(List<String> ids);
|
||||
|
||||
long countByAvailableTrue();
|
||||
|
||||
long countByAvailableFalse();
|
||||
|
||||
long countByLocationWithin(GeoPoint point, String distance);
|
||||
|
||||
long countByLocationWithin(Point point, Distance distance);
|
||||
|
||||
long countByLocationNear(GeoBox box);
|
||||
|
||||
long countByLocationNear(Box box);
|
||||
|
||||
long countByLocationNear(Point point, Distance distance);
|
||||
|
||||
long countByLocationNear(GeoPoint point, String distance);
|
||||
}
|
||||
/*
|
||||
* Copyright 2013 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
|
||||
*
|
||||
* http://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.custom;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.annotations.Query;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoBox;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
import org.springframework.data.geo.Box;
|
||||
import org.springframework.data.geo.Distance;
|
||||
import org.springframework.data.geo.Point;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Kevin Leturc
|
||||
*/
|
||||
public interface SampleCustomMethodRepository extends ElasticsearchRepository<SampleEntity, String> {
|
||||
|
||||
Page<SampleEntity> findByType(String type, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByTypeNot(String type, Pageable pageable);
|
||||
|
||||
@Query("{\"bool\" : {\"must\" : {\"term\" : {\"message\" : \"?0\"}}}}")
|
||||
Page<SampleEntity> findByMessage(String message, Pageable pageable);
|
||||
|
||||
@Query("{\"bool\" : {\"must\" : {\"term\" : {\"message\" : \"?0\"}}}}")
|
||||
List<SampleEntity> findByMessage(String message);
|
||||
|
||||
Page<SampleEntity> findByAvailable(boolean available, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByRateLessThan(int rate, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByRateBefore(int rate, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByRateAfter(int rate, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByMessageLike(String message, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByMessageStartingWith(String message, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByMessageEndingWith(String message, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByMessageContaining(String message, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByIdIn(List<String> ids, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByIdNotIn(List<String> ids, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByAvailableTrue(Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByAvailableFalse(Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByMessageOrderByTypeAsc(String message, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocation(GeoPoint point, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocationAndMessage(GeoPoint point, String msg, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocationWithin(GeoPoint point, String distance, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocationWithin(Point point, Distance distance, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocationNear(GeoBox box, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocationNear(Box box, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocationNear(Point point, Distance distance, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByLocationNear(GeoPoint point, String distance, Pageable pageable);
|
||||
|
||||
Stream<SampleEntity> findByType(String type);
|
||||
|
||||
long countByType(String type);
|
||||
|
||||
long countByTypeNot(String type);
|
||||
|
||||
long countByAvailable(boolean available);
|
||||
|
||||
long countByRateLessThan(int rate);
|
||||
|
||||
long countByRateBefore(int rate);
|
||||
|
||||
long countByRateAfter(int rate);
|
||||
|
||||
long countByMessageLike(String message);
|
||||
|
||||
long countByMessageStartingWith(String message);
|
||||
|
||||
long countByMessageEndingWith(String message);
|
||||
|
||||
long countByMessageContaining(String message);
|
||||
|
||||
long countByIdIn(List<String> ids);
|
||||
|
||||
long countByIdNotIn(List<String> ids);
|
||||
|
||||
long countByAvailableTrue();
|
||||
|
||||
long countByAvailableFalse();
|
||||
|
||||
long countByLocationWithin(GeoPoint point, String distance);
|
||||
|
||||
long countByLocationWithin(Point point, Distance distance);
|
||||
|
||||
long countByLocationNear(GeoBox box);
|
||||
|
||||
long countByLocationNear(Box box);
|
||||
|
||||
long countByLocationNear(Point point, Distance distance);
|
||||
|
||||
long countByLocationNear(GeoPoint point, String distance);
|
||||
}
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
/*
|
||||
* Copyright 2013-2014 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
|
||||
*
|
||||
* http://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.nondocument;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.elasticsearch.entities.NonDocumentEntity;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Lazy
|
||||
public interface NonDocumentEntityRepository extends ElasticsearchRepository<NonDocumentEntity, String> {
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2013-2014 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
|
||||
*
|
||||
* http://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.nondocument;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.data.elasticsearch.entities.NonDocumentEntity;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Lazy
|
||||
public interface NonDocumentEntityRepository extends ElasticsearchRepository<NonDocumentEntity, String> {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
/*
|
||||
* Copyright 2013-2017 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
|
||||
*
|
||||
* http://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.sample;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public interface SampleElasticsearchRepository extends ElasticsearchRepository<SampleEntity, String> {
|
||||
|
||||
long deleteSampleEntityById(String id);
|
||||
|
||||
List<SampleEntity> deleteByAvailable(boolean available);
|
||||
|
||||
List<SampleEntity> deleteByMessage(String message);
|
||||
|
||||
void deleteByType(String type);
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2013-2017 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
|
||||
*
|
||||
* http://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.sample;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
||||
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public interface SampleElasticsearchRepository extends ElasticsearchRepository<SampleEntity, String> {
|
||||
|
||||
long deleteSampleEntityById(String id);
|
||||
|
||||
List<SampleEntity> deleteByAvailable(boolean available);
|
||||
|
||||
List<SampleEntity> deleteByMessage(String message);
|
||||
|
||||
void deleteByType(String type);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
/*
|
||||
* Copyright 2013-2017 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
|
||||
*
|
||||
* http://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.repository.support;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
||||
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ElasticsearchRepositoryFactoryTests {
|
||||
|
||||
@Mock
|
||||
private ElasticsearchOperations operations;
|
||||
private ElasticsearchConverter converter;
|
||||
private ElasticsearchRepositoryFactory factory;
|
||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext = new SimpleElasticsearchMappingContext();
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
converter = new MappingElasticsearchConverter(mappingContext);
|
||||
when(operations.getElasticsearchConverter()).thenReturn(converter);
|
||||
factory = new ElasticsearchRepositoryFactory(operations);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionGivenQueryDslRepository() {
|
||||
// given
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(QuerydslPredicateExecutor.class);
|
||||
// when
|
||||
factory.getRepositoryBaseClass(metadata);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2013-2017 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
|
||||
*
|
||||
* http://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.repository.support;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
|
||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
||||
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ElasticsearchRepositoryFactoryTests {
|
||||
|
||||
@Mock
|
||||
private ElasticsearchOperations operations;
|
||||
private ElasticsearchConverter converter;
|
||||
private ElasticsearchRepositoryFactory factory;
|
||||
MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext = new SimpleElasticsearchMappingContext();
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
converter = new MappingElasticsearchConverter(mappingContext);
|
||||
when(operations.getElasticsearchConverter()).thenReturn(converter);
|
||||
factory = new ElasticsearchRepositoryFactory(operations);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionGivenQueryDslRepository() {
|
||||
// given
|
||||
RepositoryMetadata metadata = new DefaultRepositoryMetadata(QuerydslPredicateExecutor.class);
|
||||
// when
|
||||
factory.getRepositoryBaseClass(metadata);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user