fixed tests

This commit is contained in:
Mathieu Fortin 2020-04-13 13:02:12 -04:00
parent 745d5edda1
commit c1d547c5f0
5 changed files with 23 additions and 21 deletions

View File

@ -84,7 +84,7 @@
<properties>
<spring-data-elasticsearch.version>3.2.6.RELEASE</spring-data-elasticsearch.version>
<jna.version>4.5.2</jna.version>
<elasticsearch.version>7.6.2</elasticsearch.version>
<elasticsearch.version>6.8.8</elasticsearch.version>
<fastjson.version>1.2.47</fastjson.version>
<spatial4j.version>0.6</spatial4j.version>
<jts.version>1.13</jts.version>

View File

@ -58,7 +58,7 @@ public class ElasticSearchManualTest {
@Test
public void givenJsonString_whenJavaObject_thenIndexDocument() throws Exception {
String jsonObject = "{\"age\":20,\"dateOfBirth\":1471466076564,\"fullName\":\"John Doe\"}";
IndexRequest request = new IndexRequest("people");
IndexRequest request = new IndexRequest("people", "Doe");
request.source(jsonObject, XContentType.JSON);
IndexResponse response = client.index(request, RequestOptions.DEFAULT);
@ -71,7 +71,7 @@ public class ElasticSearchManualTest {
@Test
public void givenDocumentId_whenJavaObject_thenDeleteDocument() throws Exception {
String jsonObject = "{\"age\":10,\"dateOfBirth\":1471455886564,\"fullName\":\"Johan Doe\"}";
IndexRequest indexRequest = new IndexRequest("people");
IndexRequest indexRequest = new IndexRequest("people", "Doe");
indexRequest.source(jsonObject, XContentType.JSON);
IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT);
@ -79,6 +79,7 @@ public class ElasticSearchManualTest {
DeleteRequest deleteRequest = new DeleteRequest("people");
deleteRequest.id(id);
deleteRequest.type("Doe");
DeleteResponse deleteResponse = client.delete(deleteRequest, RequestOptions.DEFAULT);
@ -95,6 +96,8 @@ public class ElasticSearchManualTest {
List<Person> results = Arrays.stream(searchHits)
.map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class))
.collect(Collectors.toList());
results.forEach(System.out::println);
}
@Test
@ -140,6 +143,7 @@ public class ElasticSearchManualTest {
final List<Person> results = Arrays.stream(response.getHits().getHits())
.map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class))
.collect(Collectors.toList());
results.forEach(System.out::println);
}
@Test
@ -152,7 +156,7 @@ public class ElasticSearchManualTest {
.field("age", "10")
.endObject();
IndexRequest indexRequest = new IndexRequest("people");
IndexRequest indexRequest = new IndexRequest("people", "Doe");
indexRequest.source(builder);
IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT);

View File

@ -79,8 +79,7 @@ public class GeoQueriesManualTest {
Coordinate topLeft = new Coordinate(74, 31.2);
Coordinate bottomRight = new Coordinate(81.1, 24);
QueryBuilder qb = QueryBuilders
.geoShapeQuery("region", new EnvelopeBuilder(topLeft, bottomRight).buildGeometry());
//.relation(ShapeRelation.WITHIN));
.geoShapeQuery("region", new EnvelopeBuilder(topLeft, bottomRight));
SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD)
.setTypes(WONDERS)

View File

@ -10,23 +10,23 @@ import static org.junit.Assert.assertNotNull;
import java.util.List;
import com.baeldung.spring.data.es.config.Config;
import com.baeldung.spring.data.es.model.Article;
import com.baeldung.spring.data.es.model.Author;
import com.baeldung.spring.data.es.service.ArticleService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.baeldung.spring.data.es.config.Config;
import com.baeldung.spring.data.es.model.Article;
import com.baeldung.spring.data.es.model.Author;
import com.baeldung.spring.data.es.service.ArticleService;
/**
*
* This Manual test requires:
@ -39,7 +39,7 @@ import com.baeldung.spring.data.es.service.ArticleService;
public class ElasticSearchManualTest {
@Autowired
private ElasticsearchTemplate elasticsearchTemplate;
private ElasticsearchRestTemplate elasticsearchTemplate;
@Autowired
private ArticleService articleService;

View File

@ -14,6 +14,11 @@ import static org.junit.Assert.assertEquals;
import java.util.List;
import java.util.Map;
import com.baeldung.spring.data.es.config.Config;
import com.baeldung.spring.data.es.model.Article;
import com.baeldung.spring.data.es.model.Author;
import com.baeldung.spring.data.es.service.ArticleService;
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.Client;
@ -25,23 +30,17 @@ import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
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.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.data.elasticsearch.core.query.SearchQuery;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.baeldung.spring.data.es.config.Config;
import com.baeldung.spring.data.es.model.Article;
import com.baeldung.spring.data.es.model.Author;
import com.baeldung.spring.data.es.service.ArticleService;
/**
*
* This Manual test requires:
@ -54,7 +53,7 @@ import com.baeldung.spring.data.es.service.ArticleService;
public class ElasticSearchQueryManualTest {
@Autowired
private ElasticsearchTemplate elasticsearchTemplate;
private ElasticsearchRestTemplate elasticsearchTemplate;
@Autowired
private ArticleService articleService;