DATAES-637 - Change branch 4.0. to use Elasticsearch 7.3.

Original PR: #302
This commit is contained in:
Peter-Josef Meisch
2019-08-15 18:39:31 +02:00
parent 9cb9c72acc
commit ce686b1f03
41 changed files with 159 additions and 96 deletions

View File

@@ -31,6 +31,7 @@ import org.springframework.data.elasticsearch.client.ClientConfiguration;
import org.springframework.data.elasticsearch.client.RestClients;
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients;
import org.springframework.data.elasticsearch.support.SearchHitsUtil;
import org.springframework.data.util.Version;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
@@ -59,7 +60,8 @@ public final class TestUtils {
try (RestHighLevelClient client = restHighLevelClient()) {
org.elasticsearch.Version version = client.info(RequestOptions.DEFAULT).getVersion();
org.elasticsearch.Version version = org.elasticsearch.Version
.fromString(client.info(RequestOptions.DEFAULT).getVersion().getNumber());
return new Version(version.major, version.minor, version.revision);
} catch (Exception e) {
@@ -91,10 +93,10 @@ public final class TestUtils {
try (RestHighLevelClient client = restHighLevelClient()) {
return 0L == client
return 0L == SearchHitsUtil.getTotalCount(client
.search(new SearchRequest(indexName)
.source(SearchSourceBuilder.searchSource().query(QueryBuilders.matchAllQuery())), RequestOptions.DEFAULT)
.getHits().getTotalHits();
.getHits());
}
}

View File

@@ -30,7 +30,6 @@ import java.util.stream.IntStream;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
import org.elasticsearch.action.delete.DeleteRequest;
import org.elasticsearch.action.get.GetRequest;
@@ -41,6 +40,7 @@ import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.get.GetResult;
import org.elasticsearch.index.query.QueryBuilders;
@@ -65,7 +65,7 @@ import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Christoph Strobl
* @author Mark Paluch
* @currentRead Fool's Fate - Robin Hobb
* @author Peter-Josef Meisch
*/
@RunWith(SpringRunner.class)
@ContextConfiguration("classpath:infrastructure.xml")
@@ -79,7 +79,9 @@ public class ReactiveElasticsearchClientTests {
static final String TYPE_I = "doc-type-1";
static final String TYPE_II = "doc-type-2";
static final Map<String, String> DOC_SOURCE;
// must be <String, Object> and not <String, String>, otherwise UpdateRequest.doc() will use the overload with
// (Object...)
static final Map<String, Object> DOC_SOURCE;
RestHighLevelClient syncClient;
ReactiveElasticsearchClient client;
@@ -135,7 +137,6 @@ public class ReactiveElasticsearchClientTests {
client.info().as(StepVerifier::create) //
.consumeNextWith(it -> {
assertThat(it.isAvailable()).isTrue();
assertThat(it.getVersion()).isGreaterThanOrEqualTo(Version.CURRENT);
}) //
.verifyComplete();

View File

@@ -179,7 +179,7 @@ public class ReactiveElasticsearchClientUnitTests {
verify(hostProvider.client(HOST)).method(HttpMethod.GET);
URI uri = hostProvider.when(HOST).captureUri();
assertThat(uri.getRawPath()).isEqualTo("/twitter/_all/1");
assertThat(uri.getRawPath()).isEqualTo("/twitter/_doc/1");
}
@Test // DATAES-488
@@ -315,7 +315,7 @@ public class ReactiveElasticsearchClientUnitTests {
verify(hostProvider.client(HOST)).method(HttpMethod.HEAD);
URI uri = hostProvider.when(HOST).captureUri();
assertThat(uri.getRawPath()).isEqualTo("/twitter/_all/1");
assertThat(uri.getRawPath()).isEqualTo("/twitter/_doc/1");
}
@Test // DATAES-488
@@ -359,7 +359,7 @@ public class ReactiveElasticsearchClientUnitTests {
});
URI uri = hostProvider.when(HOST).captureUri();
assertThat(uri.getRawPath()).isEqualTo("/twitter/10/_create");
assertThat(uri.getRawPath()).isEqualTo("/twitter/_doc/10/_create");
}
@Test // DATAES-488
@@ -378,7 +378,7 @@ public class ReactiveElasticsearchClientUnitTests {
});
URI uri = hostProvider.when(HOST).captureUri();
assertThat(uri.getRawPath()).isEqualTo("/twitter/10");
assertThat(uri.getRawPath()).isEqualTo("/twitter/_doc/10");
}
@Test // DATAES-488

View File

@@ -33,6 +33,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.lucene.search.TotalHits;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.get.MultiGetItemResponse;
import org.elasticsearch.action.get.MultiGetResponse;
@@ -51,7 +52,6 @@ import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Version;
@@ -113,7 +113,7 @@ public class DefaultResultMapperTests {
// given
SearchHit[] hits = { createCarHit("Ford", "Grat"), createCarHit("BMW", "Arrow") };
SearchHits searchHits = mock(SearchHits.class);
when(searchHits.getTotalHits()).thenReturn(2L);
when(searchHits.getTotalHits()).thenReturn(new TotalHits(2L, TotalHits.Relation.EQUAL_TO));
when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
when(response.getHits()).thenReturn(searchHits);
@@ -135,7 +135,7 @@ public class DefaultResultMapperTests {
// given
SearchHit[] hits = { createCarHit("Ford", "Grat"), createCarHit("BMW", "Arrow") };
SearchHits searchHits = mock(SearchHits.class);
when(searchHits.getTotalHits()).thenReturn(2L);
when(searchHits.getTotalHits()).thenReturn(new TotalHits(2L, TotalHits.Relation.EQUAL_TO));
when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
when(response.getHits()).thenReturn(searchHits);
@@ -154,7 +154,7 @@ public class DefaultResultMapperTests {
// given
SearchHit[] hits = { createCarPartialHit("Ford", "Grat"), createCarPartialHit("BMW", "Arrow") };
SearchHits searchHits = mock(SearchHits.class);
when(searchHits.getTotalHits()).thenReturn(2L);
when(searchHits.getTotalHits()).thenReturn(new TotalHits(2L, TotalHits.Relation.EQUAL_TO));
when(searchHits.iterator()).thenReturn(new ArrayIterator(hits));
when(response.getHits()).thenReturn(searchHits);
@@ -247,7 +247,7 @@ public class DefaultResultMapperTests {
when(hit2.getVersion()).thenReturn(5678L);
SearchHits searchHits = mock(SearchHits.class);
when(searchHits.getTotalHits()).thenReturn(2L);
when(searchHits.getTotalHits()).thenReturn(new TotalHits(2L, TotalHits.Relation.EQUAL_TO));
when(searchHits.iterator()).thenReturn(Arrays.asList(hit1, hit2).iterator());
SearchResponse searchResponse = mock(SearchResponse.class);

View File

@@ -2624,7 +2624,7 @@ public class ElasticsearchTemplateTests {
// then
assertThat(created).isTrue();
Map setting = elasticsearchTemplate.getSetting(UseServerConfigurationEntity.class);
assertThat(setting.get("index.number_of_shards")).isEqualTo("5");
assertThat(setting.get("index.number_of_shards")).isEqualTo("1");
assertThat(setting.get("index.number_of_replicas")).isEqualTo("1");
}

View File

@@ -27,7 +27,7 @@ import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
import org.elasticsearch.common.geo.GeoHashUtils;
import org.elasticsearch.geo.utils.Geohash;
import org.elasticsearch.index.query.QueryBuilders;
import org.junit.Before;
import org.junit.Test;
@@ -86,7 +86,7 @@ public class ElasticsearchTemplateGeoTests {
double[] lonLatArray = { 0.100000, 51.000000 };
String latLonString = "51.000000, 0.100000";
String geohash = "u10j46mkfekr";
GeoHashUtils.stringEncode(0.100000, 51.000000);
Geohash.stringEncode(0.100000, 51.000000);
LocationMarkerEntity location1 = LocationMarkerEntity.builder() //
.id("1").name("Artur Konczak") //
.locationAsString(latLonString) //
@@ -258,7 +258,7 @@ public class ElasticsearchTemplateGeoTests {
// given
loadClassBaseEntities();
CriteriaQuery geoLocationCriteriaQuery3 = new CriteriaQuery(new Criteria("location")
.boundedBy(GeoHashUtils.stringEncode(0, 53.5171d), GeoHashUtils.stringEncode(0.2062d, 49.5171d)));
.boundedBy(Geohash.stringEncode(0, 53.5171d), Geohash.stringEncode(0.2062d, 49.5171d)));
// when
List<AuthorMarkerEntity> geoAuthorsForGeoCriteria3 = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery3,