DATAES-285 - upgrade to elasticsearch 5.x
This commit is contained in:
committed by
Mohsin Husen
parent
17603ca8a9
commit
089d7746be
@@ -20,7 +20,9 @@ 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;
|
||||
@@ -37,7 +39,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:/repository-test-nested-object.xml")
|
||||
@ContextConfiguration("classpath:/repository-test-nested-object-books.xml")
|
||||
public class InnerObjectTests {
|
||||
|
||||
@Autowired private SampleElasticSearchBookRepository bookRepository;
|
||||
|
||||
@@ -28,6 +28,7 @@ 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;
|
||||
@@ -129,7 +130,7 @@ public class NestedObjectTests {
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(Person.class);
|
||||
|
||||
final QueryBuilder builder = nestedQuery("car", boolQuery().must(termQuery("car.name", "saturn")).must(termQuery("car.model", "imprezza")));
|
||||
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);
|
||||
@@ -186,8 +187,8 @@ public class NestedObjectTests {
|
||||
|
||||
//then
|
||||
final BoolQueryBuilder builder = boolQuery();
|
||||
builder.must(nestedQuery("girlFriends", termQuery("girlFriends.type", "temp")))
|
||||
.must(nestedQuery("girlFriends.cars", termQuery("girlFriends.cars.name", "Ford".toLowerCase())));
|
||||
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)
|
||||
@@ -325,7 +326,7 @@ public class NestedObjectTests {
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(Person.class);
|
||||
|
||||
final QueryBuilder builder = nestedQuery("books", boolQuery().must(termQuery("books.name", "java")));
|
||||
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);
|
||||
@@ -373,7 +374,7 @@ public class NestedObjectTests {
|
||||
elasticsearchTemplate.refresh(Book.class);
|
||||
//then
|
||||
final SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(nestedQuery("buckets", termQuery("buckets.1", "test3")))
|
||||
.withQuery(nestedQuery("buckets", termQuery("buckets.1", "test3"),ScoreMode.None))
|
||||
.build();
|
||||
final Page<Book> books = elasticsearchTemplate.queryForPage(searchQuery, Book.class);
|
||||
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* 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.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
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.ScriptedField;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Document(indexName = "test-index", type = "test-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SampleEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String type;
|
||||
private String message;
|
||||
private int rate;
|
||||
@ScriptedField
|
||||
private Long scriptedRate;
|
||||
private boolean available;
|
||||
private String highlightedMessage;
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getRate() {
|
||||
return rate;
|
||||
}
|
||||
|
||||
public void setRate(int rate) {
|
||||
this.rate = rate;
|
||||
}
|
||||
|
||||
public Long getScriptedRate() {
|
||||
return scriptedRate;
|
||||
}
|
||||
|
||||
public void setScriptedRate(Long scriptedRate) {
|
||||
this.scriptedRate = scriptedRate;
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
public void setAvailable(boolean available) {
|
||||
this.available = available;
|
||||
}
|
||||
|
||||
public String getHighlightedMessage() {
|
||||
return highlightedMessage;
|
||||
}
|
||||
|
||||
public void setHighlightedMessage(String highlightedMessage) {
|
||||
this.highlightedMessage = highlightedMessage;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof SampleEntity)) {
|
||||
return false;
|
||||
}
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
SampleEntity rhs = (SampleEntity) obj;
|
||||
return new EqualsBuilder().append(this.id, rhs.id).append(this.type, rhs.type).append(this.message, rhs.message)
|
||||
.append(this.rate, rhs.rate).append(this.available, rhs.available).append(this.version, rhs.version).isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder().append(id).append(type).append(message).append(rate).append(available).append(version)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SampleEntity{" +
|
||||
"id='" + id + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
", message='" + message + '\'' +
|
||||
", rate=" + rate +
|
||||
", available=" + available +
|
||||
", highlightedMessage='" + highlightedMessage + '\'' +
|
||||
", version=" + version +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
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.ScriptedField;
|
||||
|
||||
/**
|
||||
* @author Gad Akuka
|
||||
*/
|
||||
@Document(indexName = "test-index", type = "test-type", indexStoreType = "memory", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SampleEntityUUIDKeyed {
|
||||
|
||||
@Id
|
||||
private UUID id;
|
||||
private String type;
|
||||
private String message;
|
||||
private int rate;
|
||||
@ScriptedField
|
||||
private Long scriptedRate;
|
||||
private boolean available;
|
||||
private String highlightedMessage;
|
||||
@Version
|
||||
private Long version;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public int getRate() {
|
||||
return rate;
|
||||
}
|
||||
|
||||
public void setRate(int rate) {
|
||||
this.rate = rate;
|
||||
}
|
||||
|
||||
public Long getScriptedRate() {
|
||||
return scriptedRate;
|
||||
}
|
||||
|
||||
public void setScriptedRate(Long scriptedRate) {
|
||||
this.scriptedRate = scriptedRate;
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
return available;
|
||||
}
|
||||
|
||||
public void setAvailable(boolean available) {
|
||||
this.available = available;
|
||||
}
|
||||
|
||||
public String getHighlightedMessage() {
|
||||
return highlightedMessage;
|
||||
}
|
||||
|
||||
public void setHighlightedMessage(String highlightedMessage) {
|
||||
this.highlightedMessage = highlightedMessage;
|
||||
}
|
||||
|
||||
public Long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(Long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof SampleEntityUUIDKeyed)) {
|
||||
return false;
|
||||
}
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
SampleEntityUUIDKeyed rhs = (SampleEntityUUIDKeyed) obj;
|
||||
return new EqualsBuilder().append(this.id, rhs.id).append(this.type, rhs.type).append(this.message, rhs.message)
|
||||
.append(this.rate, rhs.rate).append(this.available, rhs.available).append(this.version, rhs.version).isEquals();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder().append(id).append(type).append(message).append(rate).append(available).append(version)
|
||||
.toHashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SampleEntity{" +
|
||||
"id='" + id + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
", message='" + message + '\'' +
|
||||
", rate=" + rate +
|
||||
", available=" + available +
|
||||
", highlightedMessage='" + highlightedMessage + '\'' +
|
||||
", version=" + version +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -15,24 +15,36 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch;
|
||||
|
||||
import static org.elasticsearch.node.NodeBuilder.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.elasticsearch.client.node.NodeClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.node.NodeValidationException;
|
||||
import org.elasticsearch.transport.Netty4Plugin;
|
||||
import org.springframework.data.elasticsearch.client.NodeClientFactoryBean;
|
||||
import static java.util.Arrays.*;
|
||||
|
||||
/**
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
public class Utils {
|
||||
|
||||
public static NodeClient getNodeClient() {
|
||||
return (NodeClient) nodeBuilder().settings(Settings.builder()
|
||||
.put("http.enabled", "false")
|
||||
.put("path.data", "target/elasticsearchTestData")
|
||||
.put("path.home", "src/test/resources/test-home-dir"))
|
||||
.clusterName(UUID.randomUUID().toString()).local(true).node()
|
||||
.client();
|
||||
public static Client getNodeClient() throws NodeValidationException {
|
||||
|
||||
String pathHome = "src/test/resources/test-home-dir";
|
||||
String pathData = "target/elasticsearchTestData";
|
||||
String clusterName = UUID.randomUUID().toString();
|
||||
|
||||
return new NodeClientFactoryBean.TestNode(
|
||||
Settings.builder()
|
||||
.put("transport.type", "netty4")
|
||||
.put("transport.type", "local")
|
||||
.put("http.type", "netty4")
|
||||
.put("path.home", pathHome)
|
||||
.put("path.data", pathData)
|
||||
.put("cluster.name", clusterName)
|
||||
.put("node.max_local_storage_nodes", 100)
|
||||
.put("script.inline", "true")
|
||||
.build(), asList(Netty4Plugin.class)).start().client();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ 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.NodeClientFactoryBean;
|
||||
import org.springframework.data.elasticsearch.client.TransportClientFactoryBean;
|
||||
import org.springframework.data.elasticsearch.repositories.sample.SampleElasticsearchRepository;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -41,12 +40,6 @@ public class ElasticsearchNamespaceHandlerTests {
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Test
|
||||
public void shouldCreatesNodeClient() {
|
||||
assertThat(context.getBean(NodeClientFactoryBean.class), is(notNullValue()));
|
||||
assertThat(context.getBean(NodeClientFactoryBean.class), is(instanceOf(NodeClientFactoryBean.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateTransportClient() {
|
||||
assertThat(context.getBean(TransportClientFactoryBean.class), is(notNullValue()));
|
||||
|
||||
@@ -20,6 +20,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.elasticsearch.node.NodeValidationException;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.BeansException;
|
||||
@@ -62,7 +63,7 @@ public class EnableElasticsearchRepositoriesTests implements ApplicationContextA
|
||||
static class Config {
|
||||
|
||||
@Bean
|
||||
public ElasticsearchOperations elasticsearchTemplate() {
|
||||
public ElasticsearchOperations elasticsearchTemplate() throws NodeValidationException {
|
||||
return new ElasticsearchTemplate(Utils.getNodeClient());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.elasticsearch.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.elasticsearch.node.NodeValidationException;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -44,7 +45,7 @@ public class EnableNestedElasticsearchRepositoriesTests {
|
||||
static class Config {
|
||||
|
||||
@Bean
|
||||
public ElasticsearchOperations elasticsearchTemplate() {
|
||||
public ElasticsearchOperations elasticsearchTemplate() throws NodeValidationException {
|
||||
return new ElasticsearchTemplate(Utils.getNodeClient());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,13 +29,13 @@ public class CustomEntityMapper implements EntityMapper {
|
||||
|
||||
@Override
|
||||
public String mapToString(Object object) throws IOException {
|
||||
//mapping Object to String
|
||||
//mapping Object to text
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T mapToObject(String source, Class<T> clazz) throws IOException {
|
||||
//mapping String to Object
|
||||
//mapping text to Object
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ public class DefaultResultMapperTests {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Document(indexName = "someIndex")
|
||||
@Document(indexName = "test-index-immutable-internal")
|
||||
@NoArgsConstructor(force = true)
|
||||
@Getter
|
||||
static class ImmutableEntity {
|
||||
|
||||
@@ -22,6 +22,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.lucene.search.join.ScoreMode;
|
||||
import org.elasticsearch.action.RoutingMissingException;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.action.update.UpdateResponse;
|
||||
@@ -80,7 +81,7 @@ public class ElasticsearchTemplateParentChildTests {
|
||||
elasticsearchTemplate.refresh(ChildEntity.class);
|
||||
|
||||
// find all parents that have the first child
|
||||
QueryBuilder query = hasChildQuery(ParentEntity.CHILD_TYPE, QueryBuilders.termQuery("name", child1name.toLowerCase()));
|
||||
QueryBuilder query = hasChildQuery(ParentEntity.CHILD_TYPE, QueryBuilders.termQuery("name", child1name.toLowerCase()), ScoreMode.None);
|
||||
List<ParentEntity> parents = elasticsearchTemplate.queryForList(new NativeSearchQuery(query), ParentEntity.class);
|
||||
|
||||
// we're expecting only the first parent as result
|
||||
|
||||
@@ -15,20 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import static org.apache.commons.lang.RandomStringUtils.*;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.elasticsearch.utils.IndexBuilder.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.elasticsearch.action.get.MultiGetItemResponse;
|
||||
import org.elasticsearch.action.get.MultiGetResponse;
|
||||
@@ -36,14 +30,13 @@ import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.index.engine.DocumentMissingException;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptType;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.highlight.HighlightBuilder;
|
||||
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
|
||||
import org.elasticsearch.search.sort.FieldSortBuilder;
|
||||
import org.elasticsearch.search.sort.SortOrder;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -55,20 +48,7 @@ import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
|
||||
import org.springframework.data.elasticsearch.core.query.Criteria;
|
||||
import org.springframework.data.elasticsearch.core.query.CriteriaQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.DeleteQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.FetchSourceFilterBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.GetQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.MoreLikeThisQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.ScriptField;
|
||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.StringQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.UpdateQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.*;
|
||||
import org.springframework.data.elasticsearch.entities.HetroEntity1;
|
||||
import org.springframework.data.elasticsearch.entities.HetroEntity2;
|
||||
import org.springframework.data.elasticsearch.entities.SampleEntity;
|
||||
@@ -77,6 +57,11 @@ import org.springframework.data.elasticsearch.entities.UseServerConfigurationEnt
|
||||
import org.springframework.data.util.CloseableIterator;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import static org.apache.commons.lang.RandomStringUtils.*;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.elasticsearch.utils.IndexBuilder.*;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
@@ -90,7 +75,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||
public class ElasticsearchTemplateTests {
|
||||
|
||||
private static final String INDEX_NAME = "test-index";
|
||||
private static final String INDEX_NAME = "test-index-sample";
|
||||
private static final String INDEX_1_NAME = "test-index-1";
|
||||
private static final String INDEX_2_NAME = "test-index-2";
|
||||
private static final String TYPE_NAME = "test-type";
|
||||
@@ -102,6 +87,7 @@ public class ElasticsearchTemplateTests {
|
||||
public void before() {
|
||||
elasticsearchTemplate.deleteIndex(SampleEntity.class);
|
||||
elasticsearchTemplate.createIndex(SampleEntity.class);
|
||||
elasticsearchTemplate.putMapping(SampleEntity.class);
|
||||
elasticsearchTemplate.deleteIndex(INDEX_1_NAME);
|
||||
elasticsearchTemplate.deleteIndex(INDEX_2_NAME);
|
||||
elasticsearchTemplate.deleteIndex(UseServerConfigurationEntity.class);
|
||||
@@ -225,8 +211,8 @@ public class ElasticsearchTemplateTests {
|
||||
for (MultiGetItemResponse response : responses.getResponses()) {
|
||||
SampleEntity entity = new SampleEntity();
|
||||
entity.setId(response.getResponse().getId());
|
||||
entity.setMessage((String) response.getResponse().getField("message").getValue());
|
||||
entity.setType((String) response.getResponse().getField("type").getValue());
|
||||
entity.setMessage((String) response.getResponse().getSource().get("message"));
|
||||
entity.setType((String) response.getResponse().getSource().get("type"));
|
||||
list.add((T) entity);
|
||||
}
|
||||
return list;
|
||||
@@ -426,7 +412,7 @@ public class ElasticsearchTemplateTests {
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||
.withSort(new FieldSortBuilder("rate").ignoreUnmapped(true).order(SortOrder.ASC)).build();
|
||||
.withSort(new FieldSortBuilder("rate").order(SortOrder.ASC)).build();
|
||||
// when
|
||||
Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class);
|
||||
// then
|
||||
@@ -465,8 +451,8 @@ public class ElasticsearchTemplateTests {
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||
.withSort(new FieldSortBuilder("rate").ignoreUnmapped(true).order(SortOrder.ASC))
|
||||
.withSort(new FieldSortBuilder("message").ignoreUnmapped(true).order(SortOrder.ASC)).build();
|
||||
.withSort(new FieldSortBuilder("rate").order(SortOrder.ASC))
|
||||
.withSort(new FieldSortBuilder("message").order(SortOrder.ASC)).build();
|
||||
// when
|
||||
Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class);
|
||||
// then
|
||||
@@ -517,12 +503,12 @@ public class ElasticsearchTemplateTests {
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(matchAllQuery())
|
||||
.withScriptField(new ScriptField("scriptedRate",
|
||||
new Script("doc['rate'].value * factor", ScriptService.ScriptType.INLINE, null, params)))
|
||||
new Script(ScriptType.INLINE, "expression", "doc['rate'] * factor", params)))
|
||||
.build();
|
||||
Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class);
|
||||
// then
|
||||
assertThat(sampleEntities.getTotalElements(), equalTo(1L));
|
||||
assertThat(sampleEntities.getContent().get(0).getScriptedRate(), equalTo(4L));
|
||||
assertThat(sampleEntities.getContent().get(0).getScriptedRate(), equalTo(4.0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -546,7 +532,6 @@ public class ElasticsearchTemplateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("By default, the search request will fail if there is no mapping associated with a field. The ignore_unmapped option allows to ignore fields that have no mapping and not sort by them")
|
||||
public void shouldReturnSortedPageableResultsGivenStringQuery() {
|
||||
// given
|
||||
String documentId = randomNumeric(5);
|
||||
@@ -563,7 +548,7 @@ public class ElasticsearchTemplateTests {
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
|
||||
StringQuery stringQuery = new StringQuery(matchAllQuery().toString(), new PageRequest(0, 10), new Sort(
|
||||
new Sort.Order(Sort.Direction.ASC, "messsage")));
|
||||
new Sort.Order(Sort.Direction.ASC, "message")));
|
||||
// when
|
||||
Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(stringQuery, SampleEntity.class);
|
||||
// then
|
||||
@@ -594,6 +579,7 @@ public class ElasticsearchTemplateTests {
|
||||
public void shouldCreateIndexGivenEntityClass() {
|
||||
// when
|
||||
boolean created = elasticsearchTemplate.createIndex(SampleEntity.class);
|
||||
elasticsearchTemplate.putMapping(SampleEntity.class);
|
||||
final Map setting = elasticsearchTemplate.getSetting(SampleEntity.class);
|
||||
// then
|
||||
assertThat(created, is(true));
|
||||
@@ -663,7 +649,7 @@ public class ElasticsearchTemplateTests {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<String> values = new ArrayList<>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
values.add((String) searchHit.field("message").value());
|
||||
values.add((String) searchHit.getSource().get("message"));
|
||||
}
|
||||
return new AggregatedPageImpl<>((List<T>) values);
|
||||
}
|
||||
@@ -753,18 +739,13 @@ public class ElasticsearchTemplateTests {
|
||||
criteriaQuery.addTypes(TYPE_NAME);
|
||||
criteriaQuery.setPageable(new PageRequest(0, 10));
|
||||
|
||||
String scrollId = elasticsearchTemplate.scan(criteriaQuery, 1000, false);
|
||||
ScrolledPage<SampleEntity> scroll = (ScrolledPage<SampleEntity>) elasticsearchTemplate.startScroll( 1000, criteriaQuery, SampleEntity.class);
|
||||
List<SampleEntity> sampleEntities = new ArrayList<>();
|
||||
boolean hasRecords = true;
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, SampleEntity.class);
|
||||
if (page.hasContent()) {
|
||||
sampleEntities.addAll(page.getContent());
|
||||
} else {
|
||||
hasRecords = false;
|
||||
}
|
||||
while (scroll.hasContent()) {
|
||||
sampleEntities.addAll(scroll.getContent());
|
||||
scroll = (ScrolledPage<SampleEntity>) elasticsearchTemplate.continueScroll(scroll.getScrollId() , 1000, SampleEntity.class);
|
||||
}
|
||||
elasticsearchTemplate.clearScroll(scrollId);
|
||||
elasticsearchTemplate.clearScroll(scroll.getScrollId());
|
||||
assertThat(sampleEntities.size(), is(equalTo(30)));
|
||||
}
|
||||
|
||||
@@ -780,26 +761,44 @@ public class ElasticsearchTemplateTests {
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withIndices(INDEX_NAME)
|
||||
.withTypes(TYPE_NAME).withPageable(new PageRequest(0, 10)).build();
|
||||
|
||||
String scrollId = elasticsearchTemplate.scan(searchQuery, 1000, false);
|
||||
ScrolledPage<SampleEntity> scroll = (ScrolledPage<SampleEntity>) elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class);
|
||||
List<SampleEntity> sampleEntities = new ArrayList<>();
|
||||
boolean hasRecords = true;
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, SampleEntity.class);
|
||||
if (page.hasContent()) {
|
||||
sampleEntities.addAll(page.getContent());
|
||||
} else {
|
||||
hasRecords = false;
|
||||
}
|
||||
while (scroll.hasContent()) {
|
||||
sampleEntities.addAll(scroll.getContent());
|
||||
scroll = (ScrolledPage<SampleEntity>) elasticsearchTemplate.continueScroll(scroll.getScrollId() , 1000, SampleEntity.class);
|
||||
}
|
||||
elasticsearchTemplate.clearScroll(scrollId);
|
||||
elasticsearchTemplate.clearScroll(scroll.getScrollId());
|
||||
assertThat(sampleEntities.size(), is(equalTo(30)));
|
||||
}
|
||||
|
||||
|
||||
final SearchResultMapper searchResultMapper = new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> result = new ArrayList<SampleEntity>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
if (response.getHits().getHits().length <= 0) {
|
||||
return new AggregatedPageImpl<T>(Collections.EMPTY_LIST, response.getScrollId());
|
||||
}
|
||||
String message = (String) searchHit.getSource().get("message");
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(searchHit.getId());
|
||||
sampleEntity.setMessage(message);
|
||||
result.add(sampleEntity);
|
||||
}
|
||||
|
||||
if (result.size() > 0) {
|
||||
return new AggregatedPageImpl<T>((List<T>) result, response.getScrollId());
|
||||
}
|
||||
return new AggregatedPageImpl<T>(Collections.EMPTY_LIST, response.getScrollId());
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
DATAES-167
|
||||
*/
|
||||
@Test
|
||||
public void shouldReturnResultsWithScanAndScrollForSpecifiedFieldsForCriteriaCriteria() {
|
||||
public void shouldReturnResultsWithScanAndScrollForSpecifiedFieldsForCriteriaQuery() {
|
||||
//given
|
||||
List<IndexQuery> entities = createSampleEntitiesWithMessage("Test message", 30);
|
||||
// when
|
||||
@@ -813,35 +812,15 @@ public class ElasticsearchTemplateTests {
|
||||
criteriaQuery.addFields("message");
|
||||
criteriaQuery.setPageable(new PageRequest(0, 10));
|
||||
|
||||
String scrollId = elasticsearchTemplate.scan(criteriaQuery, 5000, false);
|
||||
Page<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, criteriaQuery, SampleEntity.class, searchResultMapper);
|
||||
String scrollId = ((ScrolledPage<?>)scroll).getScrollId();
|
||||
List<SampleEntity> sampleEntities = new ArrayList<>();
|
||||
boolean hasRecords = true;
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> result = new ArrayList<>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
String message = searchHit.getFields().get("message").getValue();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(searchHit.getId());
|
||||
sampleEntity.setMessage(message);
|
||||
result.add(sampleEntity);
|
||||
}
|
||||
|
||||
if (result.size() > 0) {
|
||||
return new AggregatedPageImpl<>((List<T>) result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
if (page != null) {
|
||||
sampleEntities.addAll(page.getContent());
|
||||
} else {
|
||||
hasRecords = false;
|
||||
while (scroll.hasContent()) {
|
||||
sampleEntities.addAll(scroll.getContent());
|
||||
scrollId = ((ScrolledPage<?>)scroll).getScrollId();
|
||||
scroll = elasticsearchTemplate.continueScroll(scrollId , 1000, SampleEntity.class, searchResultMapper);
|
||||
}
|
||||
}
|
||||
elasticsearchTemplate.clearScroll(scrollId);
|
||||
elasticsearchTemplate. clearScroll(scrollId);
|
||||
assertThat(sampleEntities.size(), is(equalTo(30)));
|
||||
}
|
||||
|
||||
@@ -865,33 +844,13 @@ public class ElasticsearchTemplateTests {
|
||||
.withPageable(new PageRequest(0, 10))
|
||||
.build();
|
||||
|
||||
String scrollId = elasticsearchTemplate.scan(searchQuery, 10000, false);
|
||||
Page<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class, searchResultMapper);
|
||||
String scrollId = ((ScrolledPage) scroll).getScrollId();
|
||||
List<SampleEntity> sampleEntities = new ArrayList<>();
|
||||
boolean hasRecords = true;
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 10000L, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> result = new ArrayList<>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
String message = searchHit.getFields().get("message").getValue();
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setId(searchHit.getId());
|
||||
sampleEntity.setMessage(message);
|
||||
result.add(sampleEntity);
|
||||
}
|
||||
|
||||
if (result.size() > 0) {
|
||||
return new AggregatedPageImpl<>((List<T>) result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
if (page != null) {
|
||||
sampleEntities.addAll(page.getContent());
|
||||
} else {
|
||||
hasRecords = false;
|
||||
}
|
||||
while (scroll.hasContent()) {
|
||||
sampleEntities.addAll(scroll.getContent());
|
||||
scrollId = ((ScrolledPage) scroll).getScrollId();
|
||||
scroll = elasticsearchTemplate.continueScroll(scrollId, 1000, SampleEntity.class, searchResultMapper);
|
||||
}
|
||||
elasticsearchTemplate.clearScroll(scrollId);
|
||||
assertThat(sampleEntities.size(), is(equalTo(30)));
|
||||
@@ -914,34 +873,13 @@ public class ElasticsearchTemplateTests {
|
||||
criteriaQuery.addTypes(TYPE_NAME);
|
||||
criteriaQuery.setPageable(new PageRequest(0, 10));
|
||||
|
||||
String scrollId = elasticsearchTemplate.scan(criteriaQuery, 5000, false);
|
||||
Page<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, criteriaQuery, SampleEntity.class, searchResultMapper);
|
||||
String scrollId = ((ScrolledPage) scroll).getScrollId();
|
||||
List<SampleEntity> sampleEntities = new ArrayList<>();
|
||||
boolean hasRecords = true;
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> chunk = new ArrayList<>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
if (response.getHits().getHits().length <= 0) {
|
||||
return null;
|
||||
}
|
||||
SampleEntity user = new SampleEntity();
|
||||
user.setId(searchHit.getId());
|
||||
user.setMessage((String) searchHit.getSource().get("message"));
|
||||
chunk.add(user);
|
||||
}
|
||||
if (chunk.size() > 0) {
|
||||
return new AggregatedPageImpl<>((List<T>) chunk);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
if (page != null) {
|
||||
sampleEntities.addAll(page.getContent());
|
||||
} else {
|
||||
hasRecords = false;
|
||||
}
|
||||
while (scroll.hasContent()) {
|
||||
sampleEntities.addAll(scroll.getContent());
|
||||
scrollId = ((ScrolledPage) scroll).getScrollId();
|
||||
scroll = elasticsearchTemplate.continueScroll(scrollId, 1000, SampleEntity.class, searchResultMapper);
|
||||
}
|
||||
elasticsearchTemplate.clearScroll(scrollId);
|
||||
assertThat(sampleEntities.size(), is(equalTo(30)));
|
||||
@@ -959,34 +897,13 @@ public class ElasticsearchTemplateTests {
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withIndices(INDEX_NAME)
|
||||
.withTypes(TYPE_NAME).withPageable(new PageRequest(0, 10)).build();
|
||||
|
||||
String scrollId = elasticsearchTemplate.scan(searchQuery, 1000, false);
|
||||
Page<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class,searchResultMapper);
|
||||
String scrollId = ((ScrolledPage) scroll).getScrollId();
|
||||
List<SampleEntity> sampleEntities = new ArrayList<>();
|
||||
boolean hasRecords = true;
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> chunk = new ArrayList<>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
if (response.getHits().getHits().length <= 0) {
|
||||
return null;
|
||||
}
|
||||
SampleEntity user = new SampleEntity();
|
||||
user.setId(searchHit.getId());
|
||||
user.setMessage((String) searchHit.getSource().get("message"));
|
||||
chunk.add(user);
|
||||
}
|
||||
if (chunk.size() > 0) {
|
||||
return new AggregatedPageImpl<>((List<T>) chunk);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
if (page != null) {
|
||||
sampleEntities.addAll(page.getContent());
|
||||
} else {
|
||||
hasRecords = false;
|
||||
}
|
||||
while (scroll.hasContent()) {
|
||||
sampleEntities.addAll(scroll.getContent());
|
||||
scrollId = ((ScrolledPage) scroll).getScrollId();
|
||||
scroll = elasticsearchTemplate.continueScroll(scrollId, 1000, SampleEntity.class, searchResultMapper);
|
||||
}
|
||||
elasticsearchTemplate.clearScroll(scrollId);
|
||||
assertThat(sampleEntities.size(), is(equalTo(30)));
|
||||
@@ -1007,16 +924,13 @@ public class ElasticsearchTemplateTests {
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
||||
criteriaQuery.setPageable(new PageRequest(0, 10));
|
||||
|
||||
String scrollId = elasticsearchTemplate.scan(criteriaQuery, 1000, false, SampleEntity.class);
|
||||
Page<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, criteriaQuery, SampleEntity.class);
|
||||
String scrollId = ((ScrolledPage) scroll).getScrollId();
|
||||
List<SampleEntity> sampleEntities = new ArrayList<>();
|
||||
boolean hasRecords = true;
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, SampleEntity.class);
|
||||
if (page.hasContent()) {
|
||||
sampleEntities.addAll(page.getContent());
|
||||
} else {
|
||||
hasRecords = false;
|
||||
}
|
||||
while (scroll.hasContent()) {
|
||||
sampleEntities.addAll(scroll.getContent());
|
||||
scrollId = ((ScrolledPage) scroll).getScrollId();
|
||||
scroll = elasticsearchTemplate.continueScroll(scrollId, 1000, SampleEntity.class);
|
||||
}
|
||||
elasticsearchTemplate.clearScroll(scrollId);
|
||||
assertThat(sampleEntities.size(), is(equalTo(30)));
|
||||
@@ -1037,16 +951,13 @@ public class ElasticsearchTemplateTests {
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||
.withPageable(new PageRequest(0, 10)).build();
|
||||
|
||||
String scrollId = elasticsearchTemplate.scan(searchQuery, 1000, false, SampleEntity.class);
|
||||
Page<SampleEntity> scroll = elasticsearchTemplate.startScroll(1000, searchQuery, SampleEntity.class);
|
||||
String scrollId = ((ScrolledPage) scroll).getScrollId();
|
||||
List<SampleEntity> sampleEntities = new ArrayList<>();
|
||||
boolean hasRecords = true;
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, SampleEntity.class);
|
||||
if (page.hasContent()) {
|
||||
sampleEntities.addAll(page.getContent());
|
||||
} else {
|
||||
hasRecords = false;
|
||||
}
|
||||
while (scroll.hasContent()) {
|
||||
sampleEntities.addAll(scroll.getContent());
|
||||
scrollId = ((ScrolledPage) scroll).getScrollId();
|
||||
scroll = elasticsearchTemplate.continueScroll(scrollId, 1000, SampleEntity.class);
|
||||
}
|
||||
elasticsearchTemplate.clearScroll(scrollId);
|
||||
assertThat(sampleEntities.size(), is(equalTo(30)));
|
||||
@@ -1175,6 +1086,7 @@ public class ElasticsearchTemplateTests {
|
||||
public void shouldPutMappingForGivenEntity() throws Exception {
|
||||
// given
|
||||
Class entity = SampleMappingEntity.class;
|
||||
elasticsearchTemplate.deleteIndex(entity);
|
||||
elasticsearchTemplate.createIndex(entity);
|
||||
// when
|
||||
assertThat(elasticsearchTemplate.putMapping(entity), is(true));
|
||||
@@ -1264,9 +1176,10 @@ public class ElasticsearchTemplateTests {
|
||||
elasticsearchTemplate.index(indexQuery);
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
|
||||
final List<HighlightBuilder.Field> message = new HighlightBuilder().field("message").fields();
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(termQuery("message", "test"))
|
||||
.withHighlightFields(new HighlightBuilder.Field("message"))
|
||||
.withHighlightFields(message.toArray(new HighlightBuilder.Field[message.size()]))
|
||||
.build();
|
||||
|
||||
Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, new SearchResultMapper() {
|
||||
@@ -1399,10 +1312,13 @@ public class ElasticsearchTemplateTests {
|
||||
|
||||
// when
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(boolQuery().must(wildcardQuery("message", "*a*")).should(wildcardQuery("message", "*b*")))
|
||||
.withQuery(boolQuery()
|
||||
.must(wildcardQuery("message", "*a*"))
|
||||
.should(wildcardQuery("message", "*b*"))
|
||||
)
|
||||
.withIndices(INDEX_NAME)
|
||||
.withTypes(TYPE_NAME)
|
||||
.withMinScore(0.5F)
|
||||
.withMinScore(2.0F)
|
||||
.build();
|
||||
|
||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class);
|
||||
@@ -1571,7 +1487,7 @@ public class ElasticsearchTemplateTests {
|
||||
elasticsearchTemplate.index(indexQuery);
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
||||
criteriaQuery.addIndices("test-index");
|
||||
criteriaQuery.addIndices(INDEX_NAME);
|
||||
// when
|
||||
long count = elasticsearchTemplate.count(criteriaQuery);
|
||||
// then
|
||||
@@ -1593,7 +1509,7 @@ public class ElasticsearchTemplateTests {
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(matchAllQuery())
|
||||
.withIndices("test-index")
|
||||
.withIndices(INDEX_NAME)
|
||||
.build();
|
||||
// when
|
||||
long count = elasticsearchTemplate.count(searchQuery);
|
||||
@@ -1615,7 +1531,7 @@ public class ElasticsearchTemplateTests {
|
||||
elasticsearchTemplate.index(indexQuery);
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria());
|
||||
criteriaQuery.addIndices("test-index");
|
||||
criteriaQuery.addIndices(INDEX_NAME);
|
||||
criteriaQuery.addTypes("test-type");
|
||||
// when
|
||||
long count = elasticsearchTemplate.count(criteriaQuery);
|
||||
@@ -1638,7 +1554,7 @@ public class ElasticsearchTemplateTests {
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(matchAllQuery())
|
||||
.withIndices("test-index")
|
||||
.withIndices(INDEX_NAME)
|
||||
.withTypes("test-type")
|
||||
.build();
|
||||
// when
|
||||
@@ -1952,11 +1868,12 @@ public class ElasticsearchTemplateTests {
|
||||
|
||||
elasticsearchTemplate.deleteIndex(SampleEntity.class);
|
||||
elasticsearchTemplate.createIndex(SampleEntity.class, settings);
|
||||
elasticsearchTemplate.putMapping(SampleEntity.class);
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
|
||||
// then
|
||||
Map map = elasticsearchTemplate.getSetting(SampleEntity.class);
|
||||
assertThat(elasticsearchTemplate.indexExists("test-index"), is(true));
|
||||
assertThat(elasticsearchTemplate.indexExists(INDEX_NAME), is(true));
|
||||
assertThat(map.containsKey("index.number_of_replicas"), is(true));
|
||||
assertThat(map.containsKey("index.number_of_shards"), is(true));
|
||||
assertThat((String) map.get("index.number_of_replicas"), is("0"));
|
||||
|
||||
@@ -33,14 +33,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.elasticsearch.builder.SampleInheritedEntityBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||
import org.springframework.data.elasticsearch.entities.*;
|
||||
import org.springframework.data.elasticsearch.entities.GeoEntity;
|
||||
import org.springframework.data.elasticsearch.entities.Group;
|
||||
import org.springframework.data.elasticsearch.entities.MinimalEntity;
|
||||
import org.springframework.data.elasticsearch.entities.SampleInheritedEntity;
|
||||
import org.springframework.data.elasticsearch.entities.SampleTransientEntity;
|
||||
import org.springframework.data.elasticsearch.entities.SimpleRecursiveEntity;
|
||||
import org.springframework.data.elasticsearch.entities.StockPrice;
|
||||
import org.springframework.data.elasticsearch.entities.User;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -59,14 +53,16 @@ public class MappingBuilderTests {
|
||||
|
||||
@Test
|
||||
public void shouldNotFailOnCircularReference() {
|
||||
elasticsearchTemplate.deleteIndex(SimpleRecursiveEntity.class);
|
||||
elasticsearchTemplate.createIndex(SimpleRecursiveEntity.class);
|
||||
elasticsearchTemplate.putMapping(SimpleRecursiveEntity.class);
|
||||
elasticsearchTemplate.refresh(SimpleRecursiveEntity.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInfiniteLoopAvoidance() throws IOException {
|
||||
final String expected = "{\"mapping\":{\"properties\":{\"message\":{\"store\":true,\"" +
|
||||
"type\":\"string\",\"index\":\"not_analyzed\"," +
|
||||
"type\":\"text\",\"index\":false," +
|
||||
"\"analyzer\":\"standard\"}}}}";
|
||||
|
||||
XContentBuilder xContentBuilder = MappingBuilder.buildMapping(SampleTransientEntity.class, "mapping", "id", null);
|
||||
@@ -121,9 +117,9 @@ public class MappingBuilderTests {
|
||||
@Test
|
||||
public void shouldBuildMappingWithSuperclass() throws IOException {
|
||||
final String expected = "{\"mapping\":{\"properties\":{\"message\":{\"store\":true,\"" +
|
||||
"type\":\"string\",\"index\":\"not_analyzed\",\"analyzer\":\"standard\"}" +
|
||||
"type\":\"text\",\"index\":false,\"analyzer\":\"standard\"}" +
|
||||
",\"createdDate\":{\"store\":false," +
|
||||
"\"type\":\"date\",\"index\":\"not_analyzed\"}}}}";
|
||||
"\"type\":\"date\",\"index\":false}}}}";
|
||||
|
||||
XContentBuilder xContentBuilder = MappingBuilder.buildMapping(SampleInheritedEntity.class, "mapping", "id", null);
|
||||
assertThat(xContentBuilder.string(), is(expected));
|
||||
@@ -186,4 +182,15 @@ public class MappingBuilderTests {
|
||||
//then
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapBooks() {
|
||||
//given
|
||||
elasticsearchTemplate.createIndex(Book.class);
|
||||
elasticsearchTemplate.putMapping(Book.class);
|
||||
//when
|
||||
|
||||
//then
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.data.elasticsearch.entities.SampleDateMappingEntity;
|
||||
public class SimpleElasticsearchDateMappingTests {
|
||||
|
||||
private static final String EXPECTED_MAPPING = "{\"mapping\":{\"properties\":{\"message\":{\"store\":true," +
|
||||
"\"type\":\"string\",\"index\":\"not_analyzed\",\"analyzer\":\"standard\"},\"customFormatDate\":{\"store\":false,\"type\":\"date\",\"format\":\"dd.MM.yyyy hh:mm\"}," +
|
||||
"\"type\":\"text\",\"index\":false,\"analyzer\":\"standard\"},\"customFormatDate\":{\"store\":false,\"type\":\"date\",\"format\":\"dd.MM.yyyy hh:mm\"}," +
|
||||
"\"defaultFormatDate\":{\"store\":false,\"type\":\"date\"},\"basicFormatDate\":{\"store\":false,\"" +
|
||||
"type\":\"date\",\"format\":\"basic_date\"}}}}";
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.SearchType;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -36,6 +37,11 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilde
|
||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
import static org.elasticsearch.search.aggregations.AggregationBuilders.terms;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
@@ -81,8 +87,8 @@ public class ElasticsearchTemplateAggregationTests {
|
||||
// given
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(matchAllQuery())
|
||||
.withSearchType(COUNT)
|
||||
.withIndices("articles").withTypes("article")
|
||||
.withSearchType(SearchType.DEFAULT)
|
||||
.withIndices("test-index-articles").withTypes("article")
|
||||
.addAggregation(terms("subjects").field("subject"))
|
||||
.build();
|
||||
// when
|
||||
|
||||
@@ -7,14 +7,14 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
||||
/**
|
||||
* @author Mewes Kochheim
|
||||
*/
|
||||
@Document(indexName = "test-completion-index", type = "annotated-completion-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-annotated-completion", type = "annotated-completion-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class AnnotatedCompletionEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
@CompletionField(payloads = true, maxInputLength = 100)
|
||||
@CompletionField(maxInputLength = 100)
|
||||
private Completion suggest;
|
||||
|
||||
private AnnotatedCompletionEntity() {
|
||||
|
||||
@@ -36,23 +36,12 @@ public class AnnotatedCompletionEntityBuilder {
|
||||
}
|
||||
|
||||
public AnnotatedCompletionEntityBuilder suggest(String[] input) {
|
||||
return suggest(input, null, null, null);
|
||||
return suggest(input, null);
|
||||
}
|
||||
|
||||
public AnnotatedCompletionEntityBuilder suggest(String[] input, String output) {
|
||||
return suggest(input, output, null, null);
|
||||
}
|
||||
|
||||
public AnnotatedCompletionEntityBuilder suggest(String[] input, String output, Object payload) {
|
||||
return suggest(input, output, payload, null);
|
||||
}
|
||||
|
||||
public AnnotatedCompletionEntityBuilder suggest(String[] input, String output, Object payload, Integer weight) {
|
||||
public AnnotatedCompletionEntityBuilder suggest(String[] input, Integer weight) {
|
||||
Completion suggest = new Completion(input);
|
||||
suggest.setOutput(output);
|
||||
suggest.setPayload(payload);
|
||||
suggest.setWeight(weight);
|
||||
|
||||
result.setSuggest(suggest);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -9,14 +9,14 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
||||
* @author Mohsin Husen
|
||||
* @author Mewes Kochheim
|
||||
*/
|
||||
@Document(indexName = "test-completion-index", type = "completion-annotation-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-completion-annotated", type = "completion-annotation-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class CompletionAnnotatedEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
@CompletionField(payloads = true)
|
||||
@CompletionField
|
||||
private Completion suggest;
|
||||
|
||||
private CompletionAnnotatedEntity() {
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
||||
/**
|
||||
* @author Mewes Kochheim
|
||||
*/
|
||||
@Document(indexName = "test-completion-index", type = "completion-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-completion", type = "completion-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class CompletionEntity {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -36,25 +36,11 @@ public class CompletionEntityAnnotatedBuilder {
|
||||
}
|
||||
|
||||
public CompletionEntityAnnotatedBuilder suggest(String[] input) {
|
||||
return suggest(input, null, null, null);
|
||||
return suggest(input, null);
|
||||
}
|
||||
|
||||
public CompletionEntityAnnotatedBuilder suggest(String[] input, String output) {
|
||||
return suggest(input, output, null, null);
|
||||
}
|
||||
|
||||
public CompletionEntityAnnotatedBuilder suggest(String[] input, String output, Object payload) {
|
||||
return suggest(input, output, payload, null);
|
||||
}
|
||||
|
||||
public CompletionEntityAnnotatedBuilder suggest(String[] input, String output, Object payload, Integer weight) {
|
||||
public CompletionEntityAnnotatedBuilder suggest(String[] input, Integer weight) {
|
||||
Completion suggest = new Completion(input);
|
||||
if (output != null) {
|
||||
suggest.setOutput(output);
|
||||
}
|
||||
if (payload != null) {
|
||||
suggest.setPayload(payload);
|
||||
}
|
||||
if (weight != null) {
|
||||
suggest.setWeight(weight);
|
||||
}
|
||||
|
||||
@@ -34,21 +34,11 @@ public class CompletionEntityBuilder {
|
||||
}
|
||||
|
||||
public CompletionEntityBuilder suggest(String[] input) {
|
||||
return suggest(input, null, null, null);
|
||||
return suggest(input, null);
|
||||
}
|
||||
|
||||
public CompletionEntityBuilder suggest(String[] input, String output) {
|
||||
return suggest(input, output, null, null);
|
||||
}
|
||||
|
||||
public CompletionEntityBuilder suggest(String[] input, String output, Object payload) {
|
||||
return suggest(input, output, payload, null);
|
||||
}
|
||||
|
||||
public CompletionEntityBuilder suggest(String[] input, String output, Object payload, Integer weight) {
|
||||
public CompletionEntityBuilder suggest(String[] input, Integer weight) {
|
||||
Completion suggest = new Completion(input);
|
||||
suggest.setOutput(output);
|
||||
suggest.setPayload(payload);
|
||||
suggest.setWeight(weight);
|
||||
|
||||
result.setSuggest(suggest);
|
||||
|
||||
@@ -22,9 +22,13 @@ import static org.junit.Assert.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.action.suggest.SuggestResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.unit.Fuzziness;
|
||||
import org.elasticsearch.search.suggest.SuggestBuilder;
|
||||
import org.elasticsearch.search.suggest.SuggestBuilders;
|
||||
import org.elasticsearch.search.suggest.SuggestionBuilder;
|
||||
import org.elasticsearch.search.suggest.completion.CompletionSuggestion;
|
||||
import org.elasticsearch.search.suggest.completion.CompletionSuggestionFuzzyBuilder;
|
||||
import org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -34,6 +38,13 @@ import org.springframework.data.elasticsearch.entities.NonDocumentEntity;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
@@ -57,8 +68,8 @@ public class ElasticsearchTemplateCompletionTests {
|
||||
List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
indexQueries.add(new CompletionEntityBuilder("1").name("Rizwan Idrees").suggest(new String[]{"Rizwan Idrees"}).buildIndex());
|
||||
indexQueries.add(new CompletionEntityBuilder("2").name("Franck Marchand").suggest(new String[]{"Franck", "Marchand"}).buildIndex());
|
||||
indexQueries.add(new CompletionEntityBuilder("3").name("Mohsin Husen").suggest(new String[]{"Mohsin", "Husen"}, "Mohsin Husen").buildIndex());
|
||||
indexQueries.add(new CompletionEntityBuilder("4").name("Artur Konczak").suggest(new String[]{"Artur", "Konczak"}, "Artur Konczak").buildIndex());
|
||||
indexQueries.add(new CompletionEntityBuilder("3").name("Mohsin Husen").suggest(new String[]{"Mohsin", "Husen"}).buildIndex());
|
||||
indexQueries.add(new CompletionEntityBuilder("4").name("Artur Konczak").suggest(new String[]{"Artur", "Konczak"}).buildIndex());
|
||||
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(CompletionEntity.class);
|
||||
@@ -76,29 +87,9 @@ public class ElasticsearchTemplateCompletionTests {
|
||||
|
||||
List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("1").name("Franck Marchand").suggest(new String[]{"Franck", "Marchand"}).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("2").name("Mohsin Husen").suggest(new String[]{"Mohsin", "Husen"}, "Mohsin Husen").buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("3").name("Rizwan Idrees").suggest(new String[]{"Rizwan", "Idrees"}, "Rizwan Idrees").buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("4").name("Artur Konczak").suggest(new String[]{"Artur", "Konczak"}, "Artur Konczak").buildIndex());
|
||||
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class);
|
||||
}
|
||||
|
||||
private void loadAnnotatedCompletionObjectEntitiesWithPayloads() {
|
||||
elasticsearchTemplate.deleteIndex(AnnotatedCompletionEntity.class);
|
||||
elasticsearchTemplate.createIndex(AnnotatedCompletionEntity.class);
|
||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class);
|
||||
elasticsearchTemplate.putMapping(AnnotatedCompletionEntity.class);
|
||||
|
||||
NonDocumentEntity nonDocumentEntity = new NonDocumentEntity();
|
||||
nonDocumentEntity.setSomeField1("Payload");
|
||||
nonDocumentEntity.setSomeField2("test");
|
||||
|
||||
List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("1").name("Mewes Kochheim1").suggest(new String[]{"Mewes Kochheim1"}, null, Double.MAX_VALUE).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("2").name("Mewes Kochheim2").suggest(new String[]{"Mewes Kochheim2"}, null, Long.MAX_VALUE).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("3").name("Mewes Kochheim3").suggest(new String[]{"Mewes Kochheim3"}, null, "Payload test").buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("4").name("Mewes Kochheim4").suggest(new String[]{"Mewes Kochheim4"}, null, nonDocumentEntity).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("2").name("Mohsin Husen").suggest(new String[]{"Mohsin", "Husen"}).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("3").name("Rizwan Idrees").suggest(new String[]{"Rizwan", "Idrees"}).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("4").name("Artur Konczak").suggest(new String[]{"Artur", "Konczak"}).buildIndex());
|
||||
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class);
|
||||
@@ -107,14 +98,14 @@ public class ElasticsearchTemplateCompletionTests {
|
||||
private void loadAnnotatedCompletionObjectEntitiesWithWeights() {
|
||||
elasticsearchTemplate.deleteIndex(AnnotatedCompletionEntity.class);
|
||||
elasticsearchTemplate.createIndex(AnnotatedCompletionEntity.class);
|
||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class);
|
||||
elasticsearchTemplate.putMapping(AnnotatedCompletionEntity.class);
|
||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class);
|
||||
|
||||
List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("1").name("Mewes Kochheim1").suggest(new String[]{"Mewes Kochheim1"}).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("2").name("Mewes Kochheim2").suggest(new String[]{"Mewes Kochheim2"}, null, null, 0).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("3").name("Mewes Kochheim3").suggest(new String[]{"Mewes Kochheim3"}, null, null, 1).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("4").name("Mewes Kochheim4").suggest(new String[]{"Mewes Kochheim4"}, null, null, Integer.MAX_VALUE).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("1").name("Mewes Kochheim1").suggest(new String[]{"Mewes Kochheim1"},4).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("2").name("Mewes Kochheim2").suggest(new String[]{"Mewes Kochheim2"}, 1).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("3").name("Mewes Kochheim3").suggest(new String[]{"Mewes Kochheim3"}, 2).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("4").name("Mewes Kochheim4").suggest(new String[]{"Mewes Kochheim4"}, Integer.MAX_VALUE).buildIndex());
|
||||
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class);
|
||||
@@ -134,81 +125,45 @@ public class ElasticsearchTemplateCompletionTests {
|
||||
public void shouldFindSuggestionsForGivenCriteriaQueryUsingCompletionEntity() {
|
||||
//given
|
||||
loadCompletionObjectEntities();
|
||||
CompletionSuggestionFuzzyBuilder completionSuggestionFuzzyBuilder = new CompletionSuggestionFuzzyBuilder("test-suggest")
|
||||
.text("m")
|
||||
.field("suggest");
|
||||
|
||||
SuggestionBuilder completionSuggestionFuzzyBuilder = SuggestBuilders.completionSuggestion("suggest").prefix("m", Fuzziness.AUTO);
|
||||
|
||||
//when
|
||||
SuggestResponse suggestResponse = elasticsearchTemplate.suggest(completionSuggestionFuzzyBuilder, CompletionEntity.class);
|
||||
final SearchResponse suggestResponse = elasticsearchTemplate.suggest(new SuggestBuilder().addSuggestion("test-suggest",completionSuggestionFuzzyBuilder), CompletionEntity.class);
|
||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||
|
||||
//then
|
||||
assertThat(options.size(), is(2));
|
||||
assertThat(options.get(0).getText().string(), isOneOf("Marchand", "Mohsin Husen"));
|
||||
assertThat(options.get(1).getText().string(), isOneOf("Marchand", "Mohsin Husen"));
|
||||
assertThat(options.get(0).getText().string(), isOneOf("Marchand", "Mohsin"));
|
||||
assertThat(options.get(1).getText().string(), isOneOf("Marchand", "Mohsin"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindSuggestionsForGivenCriteriaQueryUsingAnnotatedCompletionEntity() {
|
||||
//given
|
||||
loadAnnotatedCompletionObjectEntities();
|
||||
CompletionSuggestionFuzzyBuilder completionSuggestionFuzzyBuilder = new CompletionSuggestionFuzzyBuilder("test-suggest")
|
||||
.text("m")
|
||||
.field("suggest");
|
||||
SuggestionBuilder completionSuggestionFuzzyBuilder = SuggestBuilders.completionSuggestion("suggest").prefix("m", Fuzziness.AUTO);
|
||||
|
||||
//when
|
||||
SuggestResponse suggestResponse = elasticsearchTemplate.suggest(completionSuggestionFuzzyBuilder, CompletionEntity.class);
|
||||
final SearchResponse suggestResponse = elasticsearchTemplate.suggest(new SuggestBuilder().addSuggestion("test-suggest", completionSuggestionFuzzyBuilder), CompletionEntity.class);
|
||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||
|
||||
//then
|
||||
assertThat(options.size(), is(2));
|
||||
assertThat(options.get(0).getText().string(), isOneOf("Marchand", "Mohsin Husen"));
|
||||
assertThat(options.get(1).getText().string(), isOneOf("Marchand", "Mohsin Husen"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindSuggestionsWithPayloadsForGivenCriteriaQueryUsingAnnotatedCompletionEntity() {
|
||||
//given
|
||||
loadAnnotatedCompletionObjectEntitiesWithPayloads();
|
||||
CompletionSuggestionFuzzyBuilder completionSuggestionFuzzyBuilder = new CompletionSuggestionFuzzyBuilder("test-suggest")
|
||||
.text("m")
|
||||
.field("suggest");
|
||||
|
||||
//when
|
||||
SuggestResponse suggestResponse = elasticsearchTemplate.suggest(completionSuggestionFuzzyBuilder, CompletionEntity.class);
|
||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||
|
||||
//then
|
||||
assertThat(options.size(), is(4));
|
||||
for (CompletionSuggestion.Entry.Option option : options) {
|
||||
if (option.getText().string().equals("Mewes Kochheim1")) {
|
||||
assertEquals(Double.MAX_VALUE, option.getPayloadAsDouble(), 0);
|
||||
} else if (option.getText().string().equals("Mewes Kochheim2")) {
|
||||
assertEquals(Long.MAX_VALUE, option.getPayloadAsLong());
|
||||
} else if (option.getText().string().equals("Mewes Kochheim3")) {
|
||||
assertEquals("Payload test", option.getPayloadAsString());
|
||||
} else if (option.getText().string().equals("Mewes Kochheim4")) {
|
||||
assertEquals("Payload", option.getPayloadAsMap().get("someField1"));
|
||||
assertEquals("test", option.getPayloadAsMap().get("someField2"));
|
||||
} else {
|
||||
fail("Unexpected option");
|
||||
}
|
||||
}
|
||||
assertThat(options.get(0).getText().string(), isOneOf("Marchand", "Mohsin"));
|
||||
assertThat(options.get(1).getText().string(), isOneOf("Marchand", "Mohsin"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindSuggestionsWithWeightsForGivenCriteriaQueryUsingAnnotatedCompletionEntity() {
|
||||
//given
|
||||
loadAnnotatedCompletionObjectEntitiesWithWeights();
|
||||
CompletionSuggestionFuzzyBuilder completionSuggestionFuzzyBuilder = new CompletionSuggestionFuzzyBuilder("test-suggest")
|
||||
.text("m")
|
||||
.field("suggest");
|
||||
SuggestionBuilder completionSuggestionFuzzyBuilder = SuggestBuilders.completionSuggestion("suggest").prefix("m", Fuzziness.AUTO);
|
||||
|
||||
//when
|
||||
SuggestResponse suggestResponse = elasticsearchTemplate.suggest(completionSuggestionFuzzyBuilder, CompletionEntity.class);
|
||||
final SearchResponse suggestResponse = elasticsearchTemplate.suggest(new SuggestBuilder().addSuggestion("test-suggest",completionSuggestionFuzzyBuilder), AnnotatedCompletionEntity.class);
|
||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||
|
||||
@@ -218,9 +173,9 @@ public class ElasticsearchTemplateCompletionTests {
|
||||
if (option.getText().string().equals("Mewes Kochheim1")) {
|
||||
assertEquals(4, option.getScore(), 0);
|
||||
} else if (option.getText().string().equals("Mewes Kochheim2")) {
|
||||
assertEquals(0, option.getScore(), 0);
|
||||
} else if (option.getText().string().equals("Mewes Kochheim3")) {
|
||||
assertEquals(1, option.getScore(), 0);
|
||||
} else if (option.getText().string().equals("Mewes Kochheim3")) {
|
||||
assertEquals(2, option.getScore(), 0);
|
||||
} else if (option.getText().string().equals("Mewes Kochheim4")) {
|
||||
assertEquals(Integer.MAX_VALUE, option.getScore(), 0);
|
||||
} else {
|
||||
|
||||
@@ -15,17 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.facet;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldIndex.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
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.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.InnerField;
|
||||
import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||
import org.springframework.data.elasticsearch.annotations.*;
|
||||
|
||||
/**
|
||||
* Simple type to test facets
|
||||
@@ -33,19 +30,20 @@ import org.springframework.data.elasticsearch.annotations.MultiField;
|
||||
* @author Artur Konczak
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Document(indexName = "articles", type = "article", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@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 = String, index = analyzed),
|
||||
mainField = @Field(type = text),
|
||||
otherFields = {
|
||||
@InnerField(suffix = "untouched", type = String, store = true, index = not_analyzed),
|
||||
@InnerField(suffix = "sort", type = String, store = true, indexAnalyzer = "keyword")
|
||||
@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<>();
|
||||
|
||||
@@ -20,24 +20,17 @@ import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.junit.Before;
|
||||
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.core.FacetedPage;
|
||||
import org.springframework.data.elasticsearch.core.facet.request.HistogramFacetRequestBuilder;
|
||||
import org.springframework.data.elasticsearch.core.facet.request.NativeFacetRequest;
|
||||
import org.springframework.data.elasticsearch.core.facet.request.RangeFacetRequestBuilder;
|
||||
import org.springframework.data.elasticsearch.core.facet.request.StatisticalFacetRequestBuilder;
|
||||
import org.springframework.data.elasticsearch.core.facet.request.TermFacetRequestBuilder;
|
||||
import org.springframework.data.elasticsearch.core.facet.result.HistogramResult;
|
||||
import org.springframework.data.elasticsearch.core.facet.result.IntervalUnit;
|
||||
import org.springframework.data.elasticsearch.core.facet.result.Range;
|
||||
import org.springframework.data.elasticsearch.core.facet.result.RangeResult;
|
||||
import org.springframework.data.elasticsearch.core.facet.result.StatisticalResult;
|
||||
import org.springframework.data.elasticsearch.core.facet.result.Term;
|
||||
import org.springframework.data.elasticsearch.core.facet.result.TermResult;
|
||||
import org.springframework.data.elasticsearch.core.facet.request.*;
|
||||
import org.springframework.data.elasticsearch.core.facet.result.*;
|
||||
import org.springframework.data.elasticsearch.core.query.DeleteQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||
@@ -260,15 +253,15 @@ public class ElasticsearchTemplateFacetTests {
|
||||
assertThat(facet.getTerms().size(), is(equalTo(3)));
|
||||
|
||||
Term term = facet.getTerms().get(0);
|
||||
assertThat(term.getTerm(), is(Integer.toString(YEAR_2000)));
|
||||
assertThat(term.getTerm(), is(Long.toString(YEAR_2000)));
|
||||
assertThat(term.getCount(), is(3l));
|
||||
|
||||
term = facet.getTerms().get(1);
|
||||
assertThat(term.getTerm(), is(Integer.toString(YEAR_2001)));
|
||||
assertThat(term.getTerm(), is(Long.toString(YEAR_2001)));
|
||||
assertThat(term.getCount(), is(2l));
|
||||
|
||||
term = facet.getTerms().get(2);
|
||||
assertThat(term.getTerm(), is(Integer.toString(YEAR_2002)));
|
||||
assertThat(term.getTerm(), is(Long.toString(YEAR_2002)));
|
||||
assertThat(term.getCount(), is(1l));
|
||||
|
||||
assertThat(facet.getTotal(), is(3l));
|
||||
@@ -292,15 +285,15 @@ public class ElasticsearchTemplateFacetTests {
|
||||
assertThat(facet.getTerms().size(), is(equalTo(3)));
|
||||
|
||||
Term term = facet.getTerms().get(0);
|
||||
assertThat(term.getTerm(), is(Integer.toString(YEAR_2000)));
|
||||
assertThat(term.getTerm(), is(Long.toString(YEAR_2000)));
|
||||
assertThat(term.getCount(), is(3l));
|
||||
|
||||
term = facet.getTerms().get(1);
|
||||
assertThat(term.getTerm(), is(Integer.toString(YEAR_2001)));
|
||||
assertThat(term.getTerm(), is(Long.toString(YEAR_2001)));
|
||||
assertThat(term.getCount(), is(2l));
|
||||
|
||||
term = facet.getTerms().get(2);
|
||||
assertThat(term.getTerm(), is(Integer.toString(YEAR_2002)));
|
||||
assertThat(term.getTerm(), is(Long.toString(YEAR_2002)));
|
||||
assertThat(term.getCount(), is(1l));
|
||||
|
||||
assertThat(facet.getTotal(), is(3l));
|
||||
@@ -325,15 +318,15 @@ public class ElasticsearchTemplateFacetTests {
|
||||
assertThat(facet.getTerms().size(), is(equalTo(7)));
|
||||
|
||||
Term term = facet.getTerms().get(0);
|
||||
assertThat(term.getTerm(), is(Integer.toString(YEAR_2000)));
|
||||
assertThat(term.getTerm(), is(Long.toString(YEAR_2000)));
|
||||
assertThat(term.getCount(), is(3l));
|
||||
|
||||
term = facet.getTerms().get(1);
|
||||
assertThat(term.getTerm(), is(Integer.toString(YEAR_2001)));
|
||||
assertThat(term.getTerm(), is(Long.toString(YEAR_2001)));
|
||||
assertThat(term.getCount(), is(2l));
|
||||
|
||||
term = facet.getTerms().get(2);
|
||||
assertThat(term.getTerm(), is(Integer.toString(YEAR_2002)));
|
||||
assertThat(term.getTerm(), is(Long.toString(YEAR_2002)));
|
||||
assertThat(term.getCount(), is(1l));
|
||||
|
||||
term = facet.getTerms().get(3);
|
||||
@@ -376,15 +369,15 @@ public class ElasticsearchTemplateFacetTests {
|
||||
assertThat(numberFacet.getTerms().size(), is(equalTo(3)));
|
||||
|
||||
Term numberTerm = numberFacet.getTerms().get(0);
|
||||
assertThat(numberTerm.getTerm(), is(Integer.toString(YEAR_2000)));
|
||||
assertThat(numberTerm.getTerm(), is(Long.toString(YEAR_2000)));
|
||||
assertThat(numberTerm.getCount(), is(3l));
|
||||
|
||||
numberTerm = numberFacet.getTerms().get(1);
|
||||
assertThat(numberTerm.getTerm(), is(Integer.toString(YEAR_2001)));
|
||||
assertThat(numberTerm.getTerm(), is(Long.toString(YEAR_2001)));
|
||||
assertThat(numberTerm.getCount(), is(2l));
|
||||
|
||||
numberTerm = numberFacet.getTerms().get(2);
|
||||
assertThat(numberTerm.getTerm(), is(Integer.toString(YEAR_2002)));
|
||||
assertThat(numberTerm.getTerm(), is(Long.toString(YEAR_2002)));
|
||||
assertThat(numberTerm.getCount(), is(1l));
|
||||
|
||||
TermResult stringFacet = (TermResult) result.getFacet(stringFacetName);
|
||||
@@ -426,15 +419,15 @@ public class ElasticsearchTemplateFacetTests {
|
||||
assertThat(facet.getTerms().size(), is(equalTo(3)));
|
||||
|
||||
Term term = facet.getTerms().get(0);
|
||||
assertThat(term.getTerm(), is(Integer.toString(YEAR_2000)));
|
||||
assertThat(term.getTerm(), is(Long.toString(YEAR_2000)));
|
||||
assertThat(term.getCount(), is(3l));
|
||||
|
||||
term = facet.getTerms().get(1);
|
||||
assertThat(term.getTerm(), is(Integer.toString(YEAR_2001)));
|
||||
assertThat(term.getTerm(), is(Long.toString(YEAR_2001)));
|
||||
assertThat(term.getCount(), is(2l));
|
||||
|
||||
term = facet.getTerms().get(2);
|
||||
assertThat(term.getTerm(), is(Integer.toString(YEAR_2002)));
|
||||
assertThat(term.getTerm(), is(Long.toString(YEAR_2002)));
|
||||
assertThat(term.getCount(), is(1l));
|
||||
|
||||
assertThat(facet.getTotal(), is(6l));
|
||||
@@ -469,6 +462,7 @@ public class ElasticsearchTemplateFacetTests {
|
||||
@Test
|
||||
public void shouldReturnAllTermsForGivenQuery() {
|
||||
// given
|
||||
|
||||
String facetName = "all_authors";
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||
.withFacet(new TermFacetRequestBuilder(facetName).applyQueryFilter().fields("authors.untouched").allTerms().build()).build();
|
||||
|
||||
@@ -55,9 +55,9 @@ public class ElasticsearchTemplateHistogramFacetTests {
|
||||
public static final long SEQUECE_CODE_UPDATE = 2;
|
||||
public static final long SEQUECE_CODE_DELETE = 3;
|
||||
public static final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
public static final String DATE_18 = "2013-10-18 18:01";
|
||||
public static final String DATE_17 = "2013-10-18 17:01";
|
||||
public static final String DATE_16 = "2013-10-18 16:01";
|
||||
public static final text DATE_18 = "2013-10-18 18:01";
|
||||
public static final text DATE_17 = "2013-10-18 17:01";
|
||||
public static final text DATE_16 = "2013-10-18 16:01";
|
||||
|
||||
|
||||
@Autowired
|
||||
@@ -87,7 +87,7 @@ public class ElasticsearchTemplateHistogramFacetTests {
|
||||
@Test
|
||||
public void shouldReturnSimpleHistogramFacetForGivenQuery() {
|
||||
// given
|
||||
String facetName = "sequenceCodeFacet";
|
||||
text facetName = "sequenceCodeFacet";
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||
.withFacet(new HistogramFacetRequestBuilder(facetName).field("sequenceCode").interval(1).build()
|
||||
).build();
|
||||
@@ -115,7 +115,7 @@ public class ElasticsearchTemplateHistogramFacetTests {
|
||||
@Test
|
||||
public void shouldReturnDateHistogramFacetForGivenQuery() throws ParseException {
|
||||
// given
|
||||
String facetName = "sequenceCodeFacet";
|
||||
text facetName = "sequenceCodeFacet";
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||
.withFacet(new HistogramFacetRequestBuilder(facetName).field("date").interval(1).timeUnit(TimeUnit.HOURS).build()
|
||||
).build();
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.data.elasticsearch.annotations.Field;
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
|
||||
@Document(indexName = "test-log-index", type = "test-log-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-log", type = "test-log-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class LogEntity {
|
||||
|
||||
private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
||||
* @author Franck Marchand
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Document(indexName = "test-geo-index", type = "geo-class-point-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-author-marker", type = "geo-class-point-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class AuthorMarkerEntity {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -15,13 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.geo;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.common.geo.GeoHashUtils;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -34,14 +30,24 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilde
|
||||
import org.springframework.data.geo.Point;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.spatial4j.core.io.GeohashUtils;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Franck Marchand
|
||||
* @author Artur Konczak
|
||||
*
|
||||
* Basic info:
|
||||
* latitude - horizontal lines (equator = 0.0, values -90.0 to 90.0)
|
||||
* longitude - vertical lines (Greenwich = 0.0, values -180 to 180)
|
||||
* London [lat,lon] = [51.50985,-0.118082] - geohash = gcpvj3448
|
||||
* Bouding Box for London = (bbox=-0.489,51.28,0.236,51.686)
|
||||
* bbox = left,bottom,right,top
|
||||
* bbox = min Longitude , min Latitude , max Longitude , max Latitude
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||
@@ -53,8 +59,8 @@ public class ElasticsearchTemplateGeoTests {
|
||||
private void loadClassBaseEntities() {
|
||||
elasticsearchTemplate.deleteIndex(AuthorMarkerEntity.class);
|
||||
elasticsearchTemplate.createIndex(AuthorMarkerEntity.class);
|
||||
elasticsearchTemplate.refresh(AuthorMarkerEntity.class);
|
||||
elasticsearchTemplate.putMapping(AuthorMarkerEntity.class);
|
||||
elasticsearchTemplate.refresh(AuthorMarkerEntity.class);
|
||||
|
||||
List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
indexQueries.add(new AuthorMarkerEntityBuilder("1").name("Franck Marchand").location(45.7806d, 3.0875d).buildIndex());
|
||||
@@ -67,37 +73,38 @@ public class ElasticsearchTemplateGeoTests {
|
||||
private void loadAnnotationBaseEntities() {
|
||||
elasticsearchTemplate.deleteIndex(LocationMarkerEntity.class);
|
||||
elasticsearchTemplate.createIndex(LocationMarkerEntity.class);
|
||||
elasticsearchTemplate.refresh(LocationMarkerEntity.class);
|
||||
elasticsearchTemplate.putMapping(LocationMarkerEntity.class);
|
||||
elasticsearchTemplate.refresh(LocationMarkerEntity.class);
|
||||
|
||||
List<IndexQuery> indexQueries = new ArrayList<>();
|
||||
double[] latLonArray = {0.100000, 51.000000};
|
||||
String lonLatString = "51.000000, 0.100000";
|
||||
String geohash = "u1044k2bd6u";
|
||||
double[] lonLatArray = {0.100000, 51.000000};
|
||||
String latLonString = "51.000000, 0.100000";
|
||||
String geohash = "u10j46mkfekr";
|
||||
GeoHashUtils.stringEncode(0.100000,51.000000);
|
||||
LocationMarkerEntity location1 = LocationMarkerEntity.builder()
|
||||
.id("1").name("Artur Konczak")
|
||||
.locationAsString(lonLatString)
|
||||
.locationAsArray(latLonArray)
|
||||
.locationWithPrefixAsDistance(geohash)
|
||||
.locationWithPrefixAsLengthOfGeoHash(geohash)
|
||||
.locationAsString(latLonString)
|
||||
.locationAsArray(lonLatArray)
|
||||
.locationAsGeoHash(geohash)
|
||||
.build();
|
||||
LocationMarkerEntity location2 = LocationMarkerEntity.builder()
|
||||
.id("2").name("Mohsin Husen")
|
||||
.locationAsString(geohash.substring(0, 5))
|
||||
.locationAsArray(latLonArray)
|
||||
.locationAsString(geohash.substring(0, 8))
|
||||
.locationAsArray(lonLatArray)
|
||||
.locationAsGeoHash(geohash.substring(0, 8))
|
||||
.build();
|
||||
LocationMarkerEntity location3 = LocationMarkerEntity.builder()
|
||||
.id("3").name("Rizwan Idrees")
|
||||
.locationAsString(geohash)
|
||||
.locationAsArray(latLonArray)
|
||||
.locationWithPrefixAsLengthOfGeoHash(geohash)
|
||||
.locationAsArray(lonLatArray)
|
||||
.locationAsGeoHash(geohash)
|
||||
.build();
|
||||
indexQueries.add(buildIndex(location1));
|
||||
indexQueries.add(buildIndex(location2));
|
||||
indexQueries.add(buildIndex(location3));
|
||||
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(AuthorMarkerEntity.class);
|
||||
elasticsearchTemplate.refresh(LocationMarkerEntity.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,7 +154,7 @@ public class ElasticsearchTemplateGeoTests {
|
||||
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery, LocationMarkerEntity.class);
|
||||
|
||||
//then
|
||||
assertThat(geoAuthorsForGeoCriteria.size(), is(2));
|
||||
assertThat(geoAuthorsForGeoCriteria.size(), is(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -193,7 +200,7 @@ public class ElasticsearchTemplateGeoTests {
|
||||
public void shouldFindAllMarkersForNativeSearchQuery() {
|
||||
//Given
|
||||
loadAnnotationBaseEntities();
|
||||
NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder().withFilter(QueryBuilders.geoBoundingBoxQuery("locationAsArray").topLeft(52, -1).bottomRight(50, 1));
|
||||
NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder().withFilter(QueryBuilders.geoBoundingBoxQuery("locationAsArray").setCorners(52, -1, 50, 1));
|
||||
//When
|
||||
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(queryBuilder.build(), LocationMarkerEntity.class);
|
||||
//Then
|
||||
@@ -223,7 +230,7 @@ public class ElasticsearchTemplateGeoTests {
|
||||
//given
|
||||
loadClassBaseEntities();
|
||||
CriteriaQuery geoLocationCriteriaQuery3 = new CriteriaQuery(
|
||||
new Criteria("location").boundedBy(GeohashUtils.encodeLatLon(53.5171d, 0), GeohashUtils.encodeLatLon(49.5171d, 0.2062d)));
|
||||
new Criteria("location").boundedBy(GeoHashUtils.stringEncode(0, 53.5171d), GeoHashUtils.stringEncode(0.2062d, 49.5171d)));
|
||||
//when
|
||||
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery3, AuthorMarkerEntity.class);
|
||||
|
||||
@@ -270,34 +277,29 @@ public class ElasticsearchTemplateGeoTests {
|
||||
public void shouldFindLocationWithGeoHashPrefix() {
|
||||
|
||||
//given
|
||||
//u1044k2bd6u - with precision = 4 -> u, u1, u10, u104
|
||||
//u1044k2bd6u - with precision = 5 -> u, u1, u10, u104, u1044
|
||||
|
||||
loadAnnotationBaseEntities();
|
||||
NativeSearchQueryBuilder locationWithPrefixAsDistancePrecision3 = new NativeSearchQueryBuilder().withFilter(QueryBuilders.geoHashCellQuery("box-one").field("locationWithPrefixAsDistance").geohash("u1044k2bd6u").precision(3));
|
||||
NativeSearchQueryBuilder locationWithPrefixAsDistancePrecision4 = new NativeSearchQueryBuilder().withFilter(QueryBuilders.geoHashCellQuery("box-one").field("locationWithPrefixAsDistance").geohash("u1044k2bd6u").precision(4));
|
||||
NativeSearchQueryBuilder locationWithPrefixAsDistancePrecision5 = new NativeSearchQueryBuilder().withFilter(QueryBuilders.geoHashCellQuery("box-one").field("locationWithPrefixAsDistance").geohash("u1044k2bd6u").precision(5));
|
||||
NativeSearchQueryBuilder location1 = new NativeSearchQueryBuilder().withFilter(QueryBuilders.geoBoundingBoxQuery("locationAsGeoHash").setCorners("u"));
|
||||
NativeSearchQueryBuilder location2 = new NativeSearchQueryBuilder().withFilter(QueryBuilders.geoBoundingBoxQuery("locationAsGeoHash").setCorners("u1"));
|
||||
NativeSearchQueryBuilder location3 = new NativeSearchQueryBuilder().withFilter(QueryBuilders.geoBoundingBoxQuery("locationAsGeoHash").setCorners("u10"));
|
||||
NativeSearchQueryBuilder location4 = new NativeSearchQueryBuilder().withFilter(QueryBuilders.geoBoundingBoxQuery("locationAsGeoHash").setCorners("u10j"));
|
||||
NativeSearchQueryBuilder location5 = new NativeSearchQueryBuilder().withFilter(QueryBuilders.geoBoundingBoxQuery("locationAsGeoHash").setCorners("u10j4"));
|
||||
NativeSearchQueryBuilder location11 = new NativeSearchQueryBuilder().withFilter(QueryBuilders.geoBoundingBoxQuery("locationAsGeoHash").setCorners("u10j46mkfek"));
|
||||
|
||||
NativeSearchQueryBuilder locationWithPrefixAsLengthOfGeoHashPrecision4 = new NativeSearchQueryBuilder().withFilter(QueryBuilders.geoHashCellQuery("box-one").field("locationWithPrefixAsLengthOfGeoHash").geohash("u1044k2bd6u").precision(4));
|
||||
NativeSearchQueryBuilder locationWithPrefixAsLengthOfGeoHashPrecision5 = new NativeSearchQueryBuilder().withFilter(QueryBuilders.geoHashCellQuery("box-one").field("locationWithPrefixAsLengthOfGeoHash").geohash("u1044k2bd6u").precision(5));
|
||||
NativeSearchQueryBuilder locationWithPrefixAsLengthOfGeoHashPrecision6 = new NativeSearchQueryBuilder().withFilter(QueryBuilders.geoHashCellQuery("box-one").field("locationWithPrefixAsLengthOfGeoHash").geohash("u1044k2bd6u").precision(6));
|
||||
//when
|
||||
List<LocationMarkerEntity> resultDistancePrecision3 = elasticsearchTemplate.queryForList(locationWithPrefixAsDistancePrecision3.build(), LocationMarkerEntity.class);
|
||||
List<LocationMarkerEntity> resultDistancePrecision4 = elasticsearchTemplate.queryForList(locationWithPrefixAsDistancePrecision4.build(), LocationMarkerEntity.class);
|
||||
List<LocationMarkerEntity> resultDistancePrecision5 = elasticsearchTemplate.queryForList(locationWithPrefixAsDistancePrecision5.build(), LocationMarkerEntity.class);
|
||||
|
||||
List<LocationMarkerEntity> resultGeoHashLengthPrecision4 = elasticsearchTemplate.queryForList(locationWithPrefixAsLengthOfGeoHashPrecision4.build(), LocationMarkerEntity.class);
|
||||
List<LocationMarkerEntity> resultGeoHashLengthPrecision5 = elasticsearchTemplate.queryForList(locationWithPrefixAsLengthOfGeoHashPrecision5.build(), LocationMarkerEntity.class);
|
||||
List<LocationMarkerEntity> resultGeoHashLengthPrecision6 = elasticsearchTemplate.queryForList(locationWithPrefixAsLengthOfGeoHashPrecision6.build(), LocationMarkerEntity.class);
|
||||
List<LocationMarkerEntity> result1 = elasticsearchTemplate.queryForList(location1.build(), LocationMarkerEntity.class);
|
||||
List<LocationMarkerEntity> result2 = elasticsearchTemplate.queryForList(location2.build(), LocationMarkerEntity.class);
|
||||
List<LocationMarkerEntity> result3 = elasticsearchTemplate.queryForList(location3.build(), LocationMarkerEntity.class);
|
||||
List<LocationMarkerEntity> result4 = elasticsearchTemplate.queryForList(location4.build(), LocationMarkerEntity.class);
|
||||
List<LocationMarkerEntity> result5 = elasticsearchTemplate.queryForList(location5.build(), LocationMarkerEntity.class);
|
||||
List<LocationMarkerEntity> result11 = elasticsearchTemplate.queryForList(location11.build(), LocationMarkerEntity.class);
|
||||
|
||||
//then
|
||||
assertThat(resultDistancePrecision3.size(), is(1));
|
||||
assertThat(resultDistancePrecision4.size(), is(1));
|
||||
assertThat(resultDistancePrecision5.size(), is(0));
|
||||
|
||||
assertThat(resultGeoHashLengthPrecision4.size(), is(2));
|
||||
assertThat(resultGeoHashLengthPrecision5.size(), is(2));
|
||||
assertThat(resultGeoHashLengthPrecision6.size(), is(0));
|
||||
assertThat(result1.size(), is(3));
|
||||
assertThat(result2.size(), is(3));
|
||||
assertThat(result3.size(), is(3));
|
||||
assertThat(result4.size(), is(3));
|
||||
assertThat(result5.size(), is(3));
|
||||
assertThat(result11.size(), is(2));
|
||||
}
|
||||
|
||||
private IndexQuery buildIndex(LocationMarkerEntity result) {
|
||||
|
||||
@@ -33,22 +33,19 @@ import org.springframework.data.elasticsearch.annotations.GeoPointField;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Document(indexName = "test-geo-index", type = "geo-annotation-point-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-location-marker", type = "geo-annotation-point-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class LocationMarkerEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
@GeoPointField
|
||||
private String locationAsString;
|
||||
@GeoPointField
|
||||
private String locationAsString;
|
||||
|
||||
@GeoPointField
|
||||
private double[] locationAsArray;
|
||||
@GeoPointField
|
||||
private double[] locationAsArray;
|
||||
|
||||
@GeoPointField(geoHashPrefix = true, geoHashPrecision = "100km")
|
||||
private String locationWithPrefixAsDistance;
|
||||
|
||||
@GeoPointField(geoHashPrefix = true, geoHashPrecision = "5")
|
||||
private String locationWithPrefixAsLengthOfGeoHash;
|
||||
@GeoPointField
|
||||
private String locationAsGeoHash;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ public class CriteriaQueryTests {
|
||||
public void before() {
|
||||
elasticsearchTemplate.deleteIndex(SampleEntity.class);
|
||||
elasticsearchTemplate.createIndex(SampleEntity.class);
|
||||
elasticsearchTemplate.putMapping(SampleEntity.class);
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
}
|
||||
|
||||
@@ -715,7 +716,7 @@ public class CriteriaQueryTests {
|
||||
|
||||
// when
|
||||
CriteriaQuery criteriaQuery = new CriteriaQuery(new Criteria("message").contains("a").or(new Criteria("message").contains("b")));
|
||||
criteriaQuery.setMinScore(0.5F);
|
||||
criteriaQuery.setMinScore(2.0F);
|
||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(criteriaQuery, SampleEntity.class);
|
||||
// then
|
||||
assertThat(page.getTotalElements(), is(1L));
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.util.Date;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldIndex;
|
||||
import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
|
||||
/**
|
||||
@@ -30,7 +29,7 @@ public class AbstractInheritedEntity {
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Field(type = FieldType.Date, index = FieldIndex.not_analyzed)
|
||||
@Field(type = FieldType.Date, index = false)
|
||||
private Date createdDate;
|
||||
|
||||
public String getId() {
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Document(indexName = "book", type = "book", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-book", type = "book", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class Book {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -18,13 +18,15 @@ package org.springframework.data.elasticsearch.entities;
|
||||
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.FieldType;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
|
||||
@Document(indexName = "double-keyed-entity", type = "double-keyed-entity", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-double-keyed-entity", type = "double-keyed-entity", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class DoubleIDEntity {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.data.elasticsearch.annotations.Setting;
|
||||
*
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Document(indexName = "test-setting-index", type = "test-setting-type")
|
||||
@Document(indexName = "test-index-dynamic-setting-and-mapping", type = "test-setting-type")
|
||||
@Setting(settingPath = "/settings/test-settings.json")
|
||||
@Mapping(mappingPath = "/mappings/test-mappings.json")
|
||||
public class DynamicSettingAndMappingEntity {
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.data.elasticsearch.annotations.Mapping;
|
||||
*
|
||||
* @author Ted Liang
|
||||
*/
|
||||
@Document(indexName = "test-field-mapping-index", type = "test-field-mapping-type")
|
||||
@Document(indexName = "test-index-field-dynamic-mapping", type = "test-field-mapping-type")
|
||||
public class FieldDynamicMappingEntity {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.data.geo.Polygon;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Document(indexName = "geo-test-index", type = "geo-test-index", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-geo", type = "geo-test-index", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class GeoEntity {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
/**
|
||||
* Created by akonczak on 21/08/2016.
|
||||
*/
|
||||
@Document(indexName = "groups", type = "group")
|
||||
@Document(indexName = "test-index-group", type = "group")
|
||||
public class Group {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -18,13 +18,15 @@ package org.springframework.data.elasticsearch.entities;
|
||||
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.FieldType;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
|
||||
@Document(indexName = "integer-keyed-entity", type = "integer-keyed-entity", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-integer-keyed-entity", type = "integer-keyed-entity", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class IntegerIDEntity {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
||||
*
|
||||
* @author Philipp Jardas
|
||||
*/
|
||||
@Document(indexName = "index", type = "type")
|
||||
@Document(indexName = "test-index-minimal", type = "type")
|
||||
public class MinimalEntity {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ParentEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@Field(type = FieldType.String, index = FieldIndex.analyzed, store = true)
|
||||
@Field(type = FieldType.text, store = true)
|
||||
private String name;
|
||||
|
||||
public ParentEntity() {
|
||||
@@ -67,10 +67,10 @@ public class ParentEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
@Field(type = FieldType.String, store = true)
|
||||
@Field(type = FieldType.text, store = true)
|
||||
@Parent(type = PARENT_TYPE)
|
||||
private String parentId;
|
||||
@Field(type = FieldType.String, index = FieldIndex.analyzed, store = true)
|
||||
@Field(type = FieldType.text, store = true)
|
||||
private String name;
|
||||
|
||||
public ChildEntity() {
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
|
||||
@Document(indexName = "person", type = "user", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-person", type = "user", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class Person {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
|
||||
@Document(indexName = "person-multiple-level-nested", type = "user", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-person-multiple-level-nested", type = "user", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class PersonMultipleLevelNested {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Document(indexName = "test-product-index", type = "test-product-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-product", type = "test-product-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class Product {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.springframework.data.elasticsearch.entities;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldIndex.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.text;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -13,13 +13,13 @@ import org.springframework.data.elasticsearch.annotations.Field;
|
||||
/**
|
||||
* @author Jakub Vavrik
|
||||
*/
|
||||
@Document(indexName = "test-datemapping", type = "mapping", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-date-mapping", type = "mapping", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SampleDateMappingEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Field(type = String, index = not_analyzed, store = true, analyzer = "standard")
|
||||
@Field(type = text, index = false, store = true, analyzer = "standard")
|
||||
private String message;
|
||||
|
||||
@Field(type = Date, format = DateFormat.custom, pattern = "dd.MM.yyyy hh:mm")
|
||||
|
||||
@@ -15,19 +15,21 @@
|
||||
*/
|
||||
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.FieldType;
|
||||
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
|
||||
@@ -39,17 +41,18 @@ import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Document(indexName = "test-index", type = "test-type", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@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 = FieldType.String)
|
||||
@Field(type = text, store = true, fielddata = true)
|
||||
private String message;
|
||||
private int rate;
|
||||
@ScriptedField
|
||||
private Long scriptedRate;
|
||||
private Double scriptedRate;
|
||||
private boolean available;
|
||||
private String highlightedMessage;
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ import java.util.UUID;
|
||||
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.FieldType;
|
||||
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
||||
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
|
||||
|
||||
@@ -46,6 +48,7 @@ public class SampleEntityUUIDKeyed {
|
||||
@Id
|
||||
private UUID id;
|
||||
private String type;
|
||||
@Field(type = FieldType.text, fielddata = true)
|
||||
private String message;
|
||||
private int rate;
|
||||
@ScriptedField
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.entities;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldIndex.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.text;
|
||||
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Field;
|
||||
@@ -24,10 +23,10 @@ import org.springframework.data.elasticsearch.annotations.Field;
|
||||
/**
|
||||
* @author Kevin Leturc
|
||||
*/
|
||||
@Document(indexName = "test-inherited-mapping", type = "mapping", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-sample-inherited", type = "mapping", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SampleInheritedEntity extends AbstractInheritedEntity {
|
||||
|
||||
@Field(type = String, index = not_analyzed, store = true, analyzer = "standard")
|
||||
@Field(type = text, index = false, store = true, analyzer = "standard")
|
||||
private String message;
|
||||
|
||||
public String getMessage() {
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.entities;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldIndex.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.text;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
@@ -26,13 +25,13 @@ import org.springframework.data.elasticsearch.annotations.Field;
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Document(indexName = "test-mapping", type = "mapping", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-sample-mapping", type = "mapping", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SampleMappingEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Field(type = String, index = not_analyzed, store = true, analyzer = "standard")
|
||||
@Field(type = text, index = false, store = true, analyzer = "standard")
|
||||
private String message;
|
||||
|
||||
private NestedEntity nested;
|
||||
@@ -55,7 +54,7 @@ public class SampleMappingEntity {
|
||||
|
||||
static class NestedEntity {
|
||||
|
||||
@Field(type = String)
|
||||
@Field(type = text)
|
||||
private String someField;
|
||||
|
||||
public String getSomeField() {
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.entities;
|
||||
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldIndex.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
|
||||
import static org.springframework.data.elasticsearch.annotations.FieldType.text;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
@@ -26,13 +25,13 @@ import org.springframework.data.elasticsearch.annotations.Field;
|
||||
/**
|
||||
* @author Jakub Vavrik
|
||||
*/
|
||||
@Document(indexName = "test-recursive-mapping", type = "mapping", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-recursive-mapping", type = "mapping", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SampleTransientEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Field(type = String, index = not_analyzed, store = true, analyzer = "standard")
|
||||
@Field(type = text, index = false, store = true, analyzer = "standard")
|
||||
private String message;
|
||||
|
||||
@Transient
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
* @author Stuart Stevenson
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Document(indexName = "circular-objects", type = "circular-object", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-simple-recursive", type = "circular-object", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class SimpleRecursiveEntity {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
||||
*
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
@Document(indexName = "#{'abz'+'-'+'entity'}", type = "#{'my'+'Type'}", shards = 1,
|
||||
@Document(indexName = "#{'test-index-abz'+'-'+'entity'}", type = "#{'my'+'Type'}", shards = 1,
|
||||
replicas = 0, refreshInterval = "-1")
|
||||
public class SpELEntity {
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
@Document(indexName = "stock", type = "price", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
@Document(indexName = "test-index-stock", type = "price", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class StockPrice {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.data.elasticsearch.annotations.Setting;
|
||||
*
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Document(indexName = "synonym-index", type = "synonym-type")
|
||||
@Document(indexName = "test-index-synonym", type = "synonym-type")
|
||||
@Setting(settingPath = "/synonyms/settings.json")
|
||||
@Mapping(mappingPath = "/synonyms/mappings.json")
|
||||
public class SynonymEntity {
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.data.elasticsearch.annotations.FieldType;
|
||||
/**
|
||||
* Created by akonczak on 21/08/2016.
|
||||
*/
|
||||
@Document(indexName = "users", type = "user")
|
||||
@Document(indexName = "test-index-user", type = "user")
|
||||
public class User {
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
||||
* @author Young Gu
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Document(indexName = "test-index")
|
||||
@Document(indexName = "test-index-immutable")
|
||||
@NoArgsConstructor(force = true)
|
||||
@Getter
|
||||
public class ImmutableEntity {
|
||||
|
||||
@@ -58,6 +58,7 @@ public class CdiRepositoryTests {
|
||||
CdiRepositoryClient client = cdiContainer.getInstance(CdiRepositoryClient.class);
|
||||
repository = client.getRepository();
|
||||
personRepository = client.getSamplePersonRepository();
|
||||
repository.deleteAll();
|
||||
qualifiedProductRepository = client.getQualifiedProductRepository();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ import javax.annotation.PreDestroy;
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.inject.Produces;
|
||||
|
||||
import org.elasticsearch.client.node.NodeClient;
|
||||
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;
|
||||
@@ -31,20 +32,20 @@ import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||
class ElasticsearchTemplateProducer {
|
||||
|
||||
@Produces
|
||||
public NodeClient createNodeClient() {
|
||||
public Client createNodeClient() throws NodeValidationException {
|
||||
return Utils.getNodeClient();
|
||||
}
|
||||
|
||||
@Produces
|
||||
public ElasticsearchOperations createElasticsearchTemplate(NodeClient nodeClient) {
|
||||
return new ElasticsearchTemplate(nodeClient);
|
||||
public ElasticsearchOperations createElasticsearchTemplate(Client client) {
|
||||
return new ElasticsearchTemplate(client);
|
||||
}
|
||||
|
||||
@Produces
|
||||
@OtherQualifier
|
||||
@PersonDB
|
||||
public ElasticsearchOperations createQualifiedElasticsearchTemplate(NodeClient nodeClient) {
|
||||
return new ElasticsearchTemplate(nodeClient);
|
||||
public ElasticsearchOperations createQualifiedElasticsearchTemplate(Client client) {
|
||||
return new ElasticsearchTemplate(client);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
||||
* @author Mason Chan
|
||||
*/
|
||||
|
||||
@Document(indexName = "test-index", type = "test-type", createIndex = false)
|
||||
@Document(indexName = "test-index-not-create", type = "test-type", createIndex = false)
|
||||
public class CreateIndexFalseEntity {
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@@ -120,7 +120,7 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
||||
Map properties = (Map) mapping.get("properties");
|
||||
assertThat(mapping, is(notNullValue()));
|
||||
assertThat(properties, is(notNullValue()));
|
||||
assertThat(((String) ((Map) properties.get("email")).get("type")), is("string"));
|
||||
assertThat(((String) ((Map) properties.get("email")).get("type")), is("text"));
|
||||
assertThat((String) ((Map) properties.get("email")).get("analyzer"), is("emailAnalyzer"));
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
||||
Map properties = (Map) mapping.get("properties");
|
||||
assertThat(mapping, is(notNullValue()));
|
||||
assertThat(properties, is(notNullValue()));
|
||||
assertThat(((String) ((Map) properties.get("email")).get("type")), is("string"));
|
||||
assertThat(((String) ((Map) properties.get("email")).get("type")), is("text"));
|
||||
assertThat((String) ((Map) properties.get("email")).get("analyzer"), is("emailAnalyzer"));
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public class DynamicSettingAndMappingEntityRepositoryTests {
|
||||
Map properties = (Map) mapping.get("properties");
|
||||
assertThat(mapping, is(notNullValue()));
|
||||
assertThat(properties, is(notNullValue()));
|
||||
assertThat(((String) ((Map) properties.get("email")).get("type")), is("string"));
|
||||
assertThat(((String) ((Map) properties.get("email")).get("type")), is("text"));
|
||||
assertThat((String) ((Map) properties.get("email")).get("analyzer"), is("emailAnalyzer"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class FieldDynamicMappingEntityRepositoryTests {
|
||||
assertThat(properties.containsKey("file"), is(true));
|
||||
Map file = (Map) properties.get("file");
|
||||
assertThat(file, is(notNullValue()));
|
||||
assertThat(((String) file.get("type")), is("string"));
|
||||
assertThat(((String) file.get("type")), is("text"));
|
||||
|
||||
assertThat(file.containsKey("fields"), is(true));
|
||||
Map fields = (Map) file.get("fields");
|
||||
@@ -79,7 +79,7 @@ public class FieldDynamicMappingEntityRepositoryTests {
|
||||
Map content = (Map) fields.get("content");
|
||||
assertThat(content, is(notNullValue()));
|
||||
|
||||
assertThat((String)content.get("type"), is("string"));
|
||||
assertThat((String)content.get("type"), is("text"));
|
||||
assertThat((String)content.get("term_vector"), is("with_positions_offsets"));
|
||||
assertThat((Boolean)content.get("store"), is(Boolean.TRUE));
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ public class ComplexCustomMethodRepositoryManualWiringTests {
|
||||
public void before() {
|
||||
elasticsearchTemplate.deleteIndex(SampleEntity.class);
|
||||
elasticsearchTemplate.createIndex(SampleEntity.class);
|
||||
elasticsearchTemplate.putMapping(SampleEntity.class);
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ public class DoubleIDRepositoryTests {
|
||||
public void before() {
|
||||
elasticsearchTemplate.deleteIndex(DoubleIDEntity.class);
|
||||
elasticsearchTemplate.createIndex(DoubleIDEntity.class);
|
||||
elasticsearchTemplate.putMapping(DoubleIDEntity.class);
|
||||
elasticsearchTemplate.refresh(DoubleIDEntity.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ public class IntegerIDRepositoryTests {
|
||||
public void before() {
|
||||
elasticsearchTemplate.deleteIndex(IntegerIDEntity.class);
|
||||
elasticsearchTemplate.createIndex(IntegerIDEntity.class);
|
||||
elasticsearchTemplate.putMapping(IntegerIDEntity.class);
|
||||
elasticsearchTemplate.refresh(IntegerIDEntity.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,16 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repository.support;
|
||||
|
||||
import static org.apache.commons.lang.RandomStringUtils.*;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.common.util.CollectionUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -32,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Order;
|
||||
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
|
||||
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
|
||||
import org.springframework.data.elasticsearch.core.query.SearchQuery;
|
||||
@@ -39,8 +36,11 @@ import org.springframework.data.elasticsearch.entities.SampleEntity;
|
||||
import org.springframework.data.elasticsearch.repositories.sample.SampleElasticsearchRepository;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import static org.apache.commons.lang.RandomStringUtils.*;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.domain.Sort.Direction.*;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
@@ -60,6 +60,7 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
public void before() {
|
||||
elasticsearchTemplate.deleteIndex(SampleEntity.class);
|
||||
elasticsearchTemplate.createIndex(SampleEntity.class);
|
||||
elasticsearchTemplate.putMapping(SampleEntity.class);
|
||||
elasticsearchTemplate.refresh(SampleEntity.class);
|
||||
}
|
||||
|
||||
@@ -103,8 +104,8 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
assertThat(entityFromElasticSearch.isPresent(), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSaveDocumentWithoutId() {
|
||||
@Test(expected = ActionRequestValidationException.class)
|
||||
public void throwExceptionWhenTryingToInsertWithVersionButWithoutId() {
|
||||
// given
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
sampleEntity.setMessage("some message");
|
||||
@@ -229,7 +230,7 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
|
||||
// then
|
||||
assertNotNull("sample entities cant be null..", sampleEntities);
|
||||
List<SampleEntity> entities = Lists.newArrayList(sampleEntities);
|
||||
List<SampleEntity> entities = CollectionUtils.iterableAsArrayList(sampleEntities);
|
||||
assertThat(entities.size(), is(2));
|
||||
}
|
||||
|
||||
@@ -508,7 +509,7 @@ public class SimpleElasticsearchRepositoryTests {
|
||||
sampleEntity2.setMessage("hello");
|
||||
repository.save(sampleEntity2);
|
||||
// when
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(new Sort(new Sort.Order(Sort.Direction.ASC, "message")));
|
||||
Iterable<SampleEntity> sampleEntities = repository.findAll(new Sort(new Order(ASC, "message")));
|
||||
// then
|
||||
assertThat(sampleEntities, is(notNullValue()));
|
||||
}
|
||||
|
||||
@@ -15,17 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.repository.support;
|
||||
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -40,6 +35,9 @@ import org.springframework.data.elasticsearch.entities.SampleEntityUUIDKeyed;
|
||||
import org.springframework.data.elasticsearch.repositories.sample.SampleUUIDKeyedElasticsearchRepository;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Gad Akuka
|
||||
@@ -243,7 +241,7 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
// when
|
||||
repository.saveAll(sampleEntities);
|
||||
// then
|
||||
Page<SampleEntityUUIDKeyed> entities = repository.search(termQuery("id", documentId), new PageRequest(0, 50));
|
||||
Page<SampleEntityUUIDKeyed> entities = repository.search(termQuery("id", documentId.toString()), new PageRequest(0, 50));
|
||||
assertNotNull(entities);
|
||||
}
|
||||
|
||||
@@ -286,7 +284,7 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
// when
|
||||
long result = repository.deleteSampleEntityUUIDKeyedById(documentId);
|
||||
// then
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("id", documentId)).build();
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("id", documentId.toString())).build();
|
||||
Page<SampleEntityUUIDKeyed> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements(), equalTo(0L));
|
||||
assertThat(result, equalTo(1L));
|
||||
@@ -400,7 +398,7 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
repository.delete(sampleEntityUUIDKeyed);
|
||||
repository.refresh();
|
||||
// then
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("id", documentId)).build();
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("id", documentId.toString())).build();
|
||||
Page<SampleEntityUUIDKeyed> sampleEntities = repository.search(searchQuery);
|
||||
assertThat(sampleEntities.getTotalElements(), equalTo(0L));
|
||||
}
|
||||
@@ -423,7 +421,7 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
repository.save(sampleEntityUUIDKeyed2);
|
||||
|
||||
// when
|
||||
Iterable<SampleEntityUUIDKeyed> sampleEntities = repository.search(termQuery("id", documentId1));
|
||||
Iterable<SampleEntityUUIDKeyed> sampleEntities = repository.search(termQuery("id", documentId1.toString()));
|
||||
// then
|
||||
assertNotNull("sample entities cant be null..", sampleEntities);
|
||||
}
|
||||
@@ -454,7 +452,6 @@ public class UUIDElasticsearchRepositoryTests {
|
||||
|
||||
@Test
|
||||
public void shouldSortByGivenField() {
|
||||
// todo
|
||||
// given
|
||||
UUID documentId = UUID.randomUUID();
|
||||
SampleEntityUUIDKeyed sampleEntityUUIDKeyed = new SampleEntityUUIDKeyed();
|
||||
|
||||
Reference in New Issue
Block a user