committed by
GitHub
parent
852273eff5
commit
79dae4ee03
@@ -17,6 +17,7 @@ package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -27,7 +28,9 @@ import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.document.DocumentField;
|
||||
import org.elasticsearch.common.text.Text;
|
||||
import org.elasticsearch.index.get.GetResult;
|
||||
import org.elasticsearch.index.shard.ShardId;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchShardTarget;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.data.elasticsearch.core.document.Document;
|
||||
import org.springframework.data.elasticsearch.core.document.DocumentAdapters;
|
||||
@@ -42,7 +45,7 @@ import org.springframework.data.elasticsearch.core.document.SearchDocument;
|
||||
*/
|
||||
public class DocumentAdaptersUnitTests {
|
||||
|
||||
@Test // DATAES-628
|
||||
@Test // DATAES-628, DATAES-848
|
||||
public void shouldAdaptGetResponse() {
|
||||
|
||||
Map<String, DocumentField> fields = Collections.singletonMap("field",
|
||||
@@ -53,6 +56,7 @@ public class DocumentAdaptersUnitTests {
|
||||
|
||||
Document document = DocumentAdapters.from(response);
|
||||
|
||||
assertThat(document.getIndex()).isEqualTo("index");
|
||||
assertThat(document.hasId()).isTrue();
|
||||
assertThat(document.getId()).isEqualTo("my-id");
|
||||
assertThat(document.hasVersion()).isTrue();
|
||||
@@ -64,7 +68,7 @@ public class DocumentAdaptersUnitTests {
|
||||
assertThat(document.getPrimaryTerm()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test // DATAES-628
|
||||
@Test // DATAES-628, DATAES-848
|
||||
public void shouldAdaptGetResponseSource() {
|
||||
|
||||
BytesArray source = new BytesArray("{\"field\":\"value\"}");
|
||||
@@ -74,6 +78,7 @@ public class DocumentAdaptersUnitTests {
|
||||
|
||||
Document document = DocumentAdapters.from(response);
|
||||
|
||||
assertThat(document.getIndex()).isEqualTo("index");
|
||||
assertThat(document.hasId()).isTrue();
|
||||
assertThat(document.getId()).isEqualTo("my-id");
|
||||
assertThat(document.hasVersion()).isTrue();
|
||||
@@ -85,7 +90,7 @@ public class DocumentAdaptersUnitTests {
|
||||
assertThat(document.getPrimaryTerm()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test // DATAES-799
|
||||
@Test // DATAES-799, DATAES-848
|
||||
public void shouldAdaptGetResult() {
|
||||
|
||||
Map<String, DocumentField> fields = Collections.singletonMap("field",
|
||||
@@ -95,6 +100,7 @@ public class DocumentAdaptersUnitTests {
|
||||
|
||||
Document document = DocumentAdapters.from(getResult);
|
||||
|
||||
assertThat(document.getIndex()).isEqualTo("index");
|
||||
assertThat(document.hasId()).isTrue();
|
||||
assertThat(document.getId()).isEqualTo("my-id");
|
||||
assertThat(document.hasVersion()).isTrue();
|
||||
@@ -106,7 +112,7 @@ public class DocumentAdaptersUnitTests {
|
||||
assertThat(document.getPrimaryTerm()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test // DATAES-799
|
||||
@Test // DATAES-799, DATAES-848
|
||||
public void shouldAdaptGetResultSource() {
|
||||
|
||||
BytesArray source = new BytesArray("{\"field\":\"value\"}");
|
||||
@@ -115,6 +121,7 @@ public class DocumentAdaptersUnitTests {
|
||||
|
||||
Document document = DocumentAdapters.from(getResult);
|
||||
|
||||
assertThat(document.getIndex()).isEqualTo("index");
|
||||
assertThat(document.hasId()).isTrue();
|
||||
assertThat(document.getId()).isEqualTo("my-id");
|
||||
assertThat(document.hasVersion()).isTrue();
|
||||
@@ -126,19 +133,22 @@ public class DocumentAdaptersUnitTests {
|
||||
assertThat(document.getPrimaryTerm()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test // DATAES-628
|
||||
public void shouldAdaptSearchResponse() {
|
||||
@Test // DATAES-628, DATAES-848
|
||||
public void shouldAdaptSearchResponse() throws IOException {
|
||||
|
||||
Map<String, DocumentField> fields = Collections.singletonMap("field",
|
||||
new DocumentField("field", Collections.singletonList("value")));
|
||||
|
||||
SearchShardTarget shard = new SearchShardTarget("node", new ShardId("index", "uuid", 42), null, null);
|
||||
SearchHit searchHit = new SearchHit(123, "my-id", new Text("type"), fields);
|
||||
searchHit.shard(shard);
|
||||
searchHit.setSeqNo(1);
|
||||
searchHit.setPrimaryTerm(2);
|
||||
searchHit.score(42);
|
||||
|
||||
SearchDocument document = DocumentAdapters.from(searchHit);
|
||||
|
||||
assertThat(document.getIndex()).isEqualTo("index");
|
||||
assertThat(document.hasId()).isTrue();
|
||||
assertThat(document.getId()).isEqualTo("my-id");
|
||||
assertThat(document.hasVersion()).isFalse();
|
||||
@@ -199,12 +209,14 @@ public class DocumentAdaptersUnitTests {
|
||||
assertThat(document.toJson()).isEqualTo("{\"string\":\"value\",\"bool\":[true,true,false]}");
|
||||
}
|
||||
|
||||
@Test // DATAES-628
|
||||
@Test // DATAES-628, DATAES-848
|
||||
public void shouldAdaptSearchResponseSource() {
|
||||
|
||||
BytesArray source = new BytesArray("{\"field\":\"value\"}");
|
||||
|
||||
SearchShardTarget shard = new SearchShardTarget("node", new ShardId("index", "uuid", 42), null, null);
|
||||
SearchHit searchHit = new SearchHit(123, "my-id", new Text("type"), Collections.emptyMap());
|
||||
searchHit.shard(shard);
|
||||
searchHit.sourceRef(source).score(42);
|
||||
searchHit.version(22);
|
||||
searchHit.setSeqNo(1);
|
||||
@@ -212,6 +224,7 @@ public class DocumentAdaptersUnitTests {
|
||||
|
||||
SearchDocument document = DocumentAdapters.from(searchHit);
|
||||
|
||||
assertThat(document.getIndex()).isEqualTo("index");
|
||||
assertThat(document.hasId()).isTrue();
|
||||
assertThat(document.getId()).isEqualTo("my-id");
|
||||
assertThat(document.hasVersion()).isTrue();
|
||||
|
||||
@@ -1728,6 +1728,23 @@ public abstract class ElasticsearchTemplateTests {
|
||||
assertThat(ids).hasSize(30);
|
||||
}
|
||||
|
||||
@Test // DATAES-848
|
||||
public void shouldReturnIndexName() {
|
||||
// given
|
||||
List<IndexQuery> entities = createSampleEntitiesWithMessage("Test message", 3);
|
||||
// when
|
||||
operations.bulkIndex(entities, index);
|
||||
indexOperations.refresh();
|
||||
NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(termQuery("message", "message"))
|
||||
.withPageable(PageRequest.of(0, 100)).build();
|
||||
// then
|
||||
SearchHits<SampleEntity> searchHits = operations.search(searchQuery, SampleEntity.class);
|
||||
|
||||
searchHits.forEach(searchHit -> {
|
||||
assertThat(searchHit.getIndex()).isEqualTo(INDEX_NAME_SAMPLE_ENTITY);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnDocumentAboveMinimalScoreGivenQuery() {
|
||||
// given
|
||||
|
||||
@@ -84,7 +84,7 @@ class SearchHitSupportTest {
|
||||
@Override
|
||||
public SearchHit<String> next() {
|
||||
String nextString = iterator.next();
|
||||
return new SearchHit<>("id", 1.0f, new Object[0], emptyMap(), nextString);
|
||||
return new SearchHit<>("index", "id", 1.0f, new Object[0], emptyMap(), nextString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class StreamQueriesTest {
|
||||
|
||||
// given
|
||||
List<SearchHit<String>> hits = new ArrayList<>();
|
||||
hits.add(new SearchHit<String>(null, 0, null, null, "one"));
|
||||
hits.add(new SearchHit<String>(null, null, 0, null, null, "one"));
|
||||
|
||||
SearchScrollHits<String> searchHits = newSearchScrollHits(hits, "1234");
|
||||
|
||||
@@ -66,7 +66,7 @@ public class StreamQueriesTest {
|
||||
|
||||
// given
|
||||
List<SearchHit<String>> hits = new ArrayList<>();
|
||||
hits.add(new SearchHit<String>(null, 0, null, null, "one"));
|
||||
hits.add(new SearchHit<String>(null, null, 0, null, null, "one"));
|
||||
|
||||
SearchScrollHits<String> searchHits = newSearchScrollHits(hits, "1234");
|
||||
|
||||
@@ -86,11 +86,11 @@ public class StreamQueriesTest {
|
||||
void shouldClearAllScrollIds() {
|
||||
|
||||
SearchScrollHits<String> searchHits1 = newSearchScrollHits(
|
||||
Collections.singletonList(new SearchHit<String>(null, 0, null, null, "one")), "s-1");
|
||||
Collections.singletonList(new SearchHit<String>(null, null, 0, null, null, "one")), "s-1");
|
||||
SearchScrollHits<String> searchHits2 = newSearchScrollHits(
|
||||
Collections.singletonList(new SearchHit<String>(null, 0, null, null, "one")), "s-2");
|
||||
Collections.singletonList(new SearchHit<String>(null, null, 0, null, null, "one")), "s-2");
|
||||
SearchScrollHits<String> searchHits3 = newSearchScrollHits(
|
||||
Collections.singletonList(new SearchHit<String>(null, 0, null, null, "one")), "s-2");
|
||||
Collections.singletonList(new SearchHit<String>(null, null, 0, null, null, "one")), "s-2");
|
||||
SearchScrollHits<String> searchHits4 = newSearchScrollHits(Collections.emptyList(), "s-3");
|
||||
|
||||
Iterator<SearchScrollHits<String>> searchScrollHitsIterator = Arrays
|
||||
@@ -115,11 +115,11 @@ public class StreamQueriesTest {
|
||||
void shouldReturnAllForRequestedSizeOf0() {
|
||||
|
||||
SearchScrollHits<String> searchHits1 = newSearchScrollHits(
|
||||
Collections.singletonList(new SearchHit<String>(null, 0, null, null, "one")), "s-1");
|
||||
Collections.singletonList(new SearchHit<String>(null, null, 0, null, null, "one")), "s-1");
|
||||
SearchScrollHits<String> searchHits2 = newSearchScrollHits(
|
||||
Collections.singletonList(new SearchHit<String>(null, 0, null, null, "one")), "s-2");
|
||||
Collections.singletonList(new SearchHit<String>(null, null, 0, null, null, "one")), "s-2");
|
||||
SearchScrollHits<String> searchHits3 = newSearchScrollHits(
|
||||
Collections.singletonList(new SearchHit<String>(null, 0, null, null, "one")), "s-2");
|
||||
Collections.singletonList(new SearchHit<String>(null, null, 0, null, null, "one")), "s-2");
|
||||
SearchScrollHits<String> searchHits4 = newSearchScrollHits(Collections.emptyList(), "s-3");
|
||||
|
||||
Iterator<SearchScrollHits<String>> searchScrollHitsIterator = Arrays
|
||||
@@ -140,11 +140,11 @@ public class StreamQueriesTest {
|
||||
void shouldOnlyReturnRequestedCount() {
|
||||
|
||||
SearchScrollHits<String> searchHits1 = newSearchScrollHits(
|
||||
Collections.singletonList(new SearchHit<String>(null, 0, null, null, "one")), "s-1");
|
||||
Collections.singletonList(new SearchHit<String>(null, null, 0, null, null, "one")), "s-1");
|
||||
SearchScrollHits<String> searchHits2 = newSearchScrollHits(
|
||||
Collections.singletonList(new SearchHit<String>(null, 0, null, null, "one")), "s-2");
|
||||
Collections.singletonList(new SearchHit<String>(null, null, 0, null, null, "one")), "s-2");
|
||||
SearchScrollHits<String> searchHits3 = newSearchScrollHits(
|
||||
Collections.singletonList(new SearchHit<String>(null, 0, null, null, "one")), "s-2");
|
||||
Collections.singletonList(new SearchHit<String>(null, null, 0, null, null, "one")), "s-2");
|
||||
SearchScrollHits<String> searchHits4 = newSearchScrollHits(Collections.emptyList(), "s-3");
|
||||
|
||||
Iterator<SearchScrollHits<String>> searchScrollHitsIterator = Arrays
|
||||
|
||||
Reference in New Issue
Block a user