DATAES-848 - Add the name of the index to SearchHit.

Original PR: #471
This commit is contained in:
Peter-Josef Meisch 2020-05-29 23:44:32 +02:00 committed by GitHub
parent 852273eff5
commit 79dae4ee03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 124 additions and 266 deletions

View File

@ -35,14 +35,16 @@ import org.springframework.util.Assert;
*/
public class SearchHit<T> {
private final String id;
@Nullable private final String index;
@Nullable private final String id;
private final float score;
private final List<Object> sortValues;
private final T content;
private final Map<String, List<String>> highlightFields = new LinkedHashMap<>();
public SearchHit(@Nullable String id, float score, @Nullable Object[] sortValues,
public SearchHit(@Nullable String index, @Nullable String id, float score, @Nullable Object[] sortValues,
@Nullable Map<String, List<String>> highlightFields, T content) {
this.index = index;
this.id = id;
this.score = score;
this.sortValues = (sortValues != null) ? Arrays.asList(sortValues) : new ArrayList<>();
@ -53,6 +55,15 @@ public class SearchHit<T> {
this.content = content;
}
/**
* @return the index name where the hit's document was found
* @since 4.1
*/
@Nullable
public String getIndex() {
return index;
}
@Nullable
public String getId() {
return id;

View File

@ -62,12 +62,13 @@ class SearchHitMapping<T> {
Assert.notNull(searchDocument, "searchDocument is null");
Assert.notNull(content, "content is null");
String index = searchDocument.getIndex();
String id = searchDocument.hasId() ? searchDocument.getId() : null;
float score = searchDocument.getScore();
Object[] sortValues = searchDocument.getSortValues();
Map<String, List<String>> highlightFields = getHighlightsAndRemapFieldNames(searchDocument);
return new SearchHit<>(id, score, sortValues, highlightFields, content);
return new SearchHit<>(index, id, score, sortValues, highlightFields, content);
}
SearchHits<T> mapHits(SearchDocumentResponse searchDocumentResponse, List<T> contents) {

View File

@ -111,6 +111,27 @@ public interface Document extends Map<String, Object> {
return false;
}
/**
* @return the index if this document was retrieved from an index
* @since 4.1
*/
@Nullable
default String getIndex() {
return null;
}
/**
* Sets the index name for this document
*
* @param index index name
* <p>
* The default implementation throws {@link UnsupportedOperationException}.
* @since 4.1
*/
default void setIndex(@Nullable String index) {
throw new UnsupportedOperationException();
}
/**
* Retrieve the identifier associated with this {@link Document}.
* <p>
@ -461,4 +482,5 @@ public interface Document extends Map<String, Object> {
* @return a JSON representation of this document.
*/
String toJson();
}

View File

@ -77,11 +77,12 @@ public class DocumentAdapters {
}
if (source.isSourceEmpty()) {
return fromDocumentFields(source, source.getId(), source.getVersion(), source.getSeqNo(),
return fromDocumentFields(source, source.getIndex(), source.getId(), source.getVersion(), source.getSeqNo(),
source.getPrimaryTerm());
}
Document document = Document.from(source.getSourceAsMap());
document.setIndex(source.getIndex());
document.setId(source.getId());
document.setVersion(source.getVersion());
document.setSeqNo(source.getSeqNo());
@ -108,11 +109,12 @@ public class DocumentAdapters {
}
if (source.isSourceEmpty()) {
return fromDocumentFields(source, source.getId(), source.getVersion(), source.getSeqNo(),
return fromDocumentFields(source, source.getIndex(), source.getId(), source.getVersion(), source.getSeqNo(),
source.getPrimaryTerm());
}
Document document = Document.from(source.getSource());
document.setIndex(source.getIndex());
document.setId(source.getId());
document.setVersion(source.getVersion());
document.setSeqNo(source.getSeqNo());
@ -157,10 +159,12 @@ public class DocumentAdapters {
if (sourceRef == null || sourceRef.length() == 0) {
return new SearchDocumentAdapter(source.getScore(), source.getSortValues(), source.getFields(), highlightFields,
fromDocumentFields(source, source.getId(), source.getVersion(), source.getSeqNo(), source.getPrimaryTerm()));
fromDocumentFields(source, source.getIndex(), source.getId(), source.getVersion(), source.getSeqNo(),
source.getPrimaryTerm()));
}
Document document = Document.from(source.getSourceAsMap());
document.setIndex(source.getIndex());
document.setId(source.getId());
if (source.getVersion() >= 0) {
@ -177,13 +181,15 @@ public class DocumentAdapters {
* Create an unmodifiable {@link Document} from {@link Iterable} of {@link DocumentField}s.
*
* @param documentFields the {@link DocumentField}s backing the {@link Document}.
* @param index
* @return the adapted {@link Document}.
*/
public static Document fromDocumentFields(Iterable<DocumentField> documentFields, String id, long version, long seqNo,
long primaryTerm) {
public static Document fromDocumentFields(Iterable<DocumentField> documentFields, String index, String id,
long version, long seqNo, long primaryTerm) {
if (documentFields instanceof Collection) {
return new DocumentFieldAdapter((Collection<DocumentField>) documentFields, id, version, seqNo, primaryTerm);
return new DocumentFieldAdapter((Collection<DocumentField>) documentFields, index, id, version, seqNo,
primaryTerm);
}
List<DocumentField> fields = new ArrayList<>();
@ -191,58 +197,49 @@ public class DocumentAdapters {
fields.add(documentField);
}
return new DocumentFieldAdapter(fields, id, version, seqNo, primaryTerm);
return new DocumentFieldAdapter(fields, index, id, version, seqNo, primaryTerm);
}
// TODO: Performance regarding keys/values/entry-set
static class DocumentFieldAdapter implements Document {
private final Collection<DocumentField> documentFields;
private final String index;
private final String id;
private final long version;
private final long seqNo;
private final long primaryTerm;
DocumentFieldAdapter(Collection<DocumentField> documentFields, String id, long version, long seqNo,
DocumentFieldAdapter(Collection<DocumentField> documentFields, String index, String id, long version, long seqNo,
long primaryTerm) {
this.documentFields = documentFields;
this.index = index;
this.id = id;
this.version = version;
this.seqNo = seqNo;
this.primaryTerm = primaryTerm;
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#hasId()
*/
@Override
public String getIndex() {
return index;
}
@Override
public boolean hasId() {
return StringUtils.hasLength(id);
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#getId()
*/
@Override
public String getId() {
return this.id;
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#hasVersion()
*/
@Override
public boolean hasVersion() {
return this.version >= 0;
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#getVersion()
*/
@Override
public long getVersion() {
@ -253,19 +250,11 @@ public class DocumentAdapters {
return this.version;
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#hasSeqNo()
*/
@Override
public boolean hasSeqNo() {
return true;
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#getSeqNo()
*/
@Override
public long getSeqNo() {
@ -276,19 +265,11 @@ public class DocumentAdapters {
return this.seqNo;
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#hasPrimaryTerm()
*/
@Override
public boolean hasPrimaryTerm() {
return true;
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#getPrimaryTerm()
*/
@Override
public long getPrimaryTerm() {
@ -299,28 +280,16 @@ public class DocumentAdapters {
return this.primaryTerm;
}
/*
* (non-Javadoc)
* @see java.util.Map#size()
*/
@Override
public int size() {
return documentFields.size();
}
/*
* (non-Javadoc)
* @see java.util.Map#isEmpty()
*/
@Override
public boolean isEmpty() {
return documentFields.isEmpty();
}
/*
* (non-Javadoc)
* @see java.util.Map#containsKey(java.lang.Object)
*/
@Override
public boolean containsKey(Object key) {
@ -333,10 +302,6 @@ public class DocumentAdapters {
return false;
}
/*
* (non-Javadoc)
* @see java.util.Map#containsValue(java.lang.Object)
*/
@Override
public boolean containsValue(Object value) {
@ -351,10 +316,6 @@ public class DocumentAdapters {
return false;
}
/*
* (non-Javadoc)
* @see java.util.Map#get(java.lang.Object)
*/
@Override
@Nullable
public Object get(Object key) {
@ -365,74 +326,42 @@ public class DocumentAdapters {
}
/*
* (non-Javadoc)
* @see java.util.Map#put(java.lang.Object, java.lang.Object)
*/
@Override
public Object put(String key, Object value) {
throw new UnsupportedOperationException();
}
/*
* (non-Javadoc)
* @see java.util.Map#remove(java.lang.Object)
*/
@Override
public Object remove(Object key) {
throw new UnsupportedOperationException();
}
/*
* (non-Javadoc)
* @see java.util.Map#putAll(Map)
*/
@Override
public void putAll(Map<? extends String, ?> m) {
throw new UnsupportedOperationException();
}
/*
* (non-Javadoc)
* @see java.util.Map#clear()
*/
@Override
public void clear() {
throw new UnsupportedOperationException();
}
/*
* (non-Javadoc)
* @see java.util.Map#keySet()
*/
@Override
public Set<String> keySet() {
return documentFields.stream().map(DocumentField::getName).collect(Collectors.toCollection(LinkedHashSet::new));
}
/*
* (non-Javadoc)
* @see java.util.Map#values()
*/
@Override
public Collection<Object> values() {
return documentFields.stream().map(DocumentFieldAdapter::getValue).collect(Collectors.toList());
}
/*
* (non-Javadoc)
* @see java.util.Map#entrySet()
*/
@Override
public Set<Entry<String, Object>> entrySet() {
return documentFields.stream().collect(Collectors.toMap(DocumentField::getName, DocumentFieldAdapter::getValue))
.entrySet();
}
/*
* (non-Javadoc)
* @see java.util.Map#forEach(java.util.function.BiConsumer)
*/
@Override
public void forEach(BiConsumer<? super String, ? super Object> action) {
@ -441,10 +370,6 @@ public class DocumentAdapters {
documentFields.forEach(field -> action.accept(field.getName(), getValue(field)));
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#toJson()
*/
@Override
public String toJson() {
@ -472,10 +397,6 @@ public class DocumentAdapters {
}
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return getClass().getSimpleName() + '@' + this.id + '#' + this.version + ' ' + toJson();
@ -517,10 +438,6 @@ public class DocumentAdapters {
this.highlightFields.putAll(highlightFields);
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#append(java.lang.String, java.lang.Object)
*/
@Override
public SearchDocument append(String key, Object value) {
delegate.append(key, value);
@ -528,281 +445,162 @@ public class DocumentAdapters {
return this;
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.SearchDocument#getScore()
*/
@Override
public float getScore() {
return score;
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.SearchDocument#getFields()
*/
@Override
public Map<String, List<Object>> getFields() {
return fields;
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.SearchDocument#getSortValues()
*/
@Override
public Object[] getSortValues() {
return sortValues;
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.SearchDocument#getHighlightFields()
*/
@Override
public Map<String, List<String>> getHighlightFields() {
return highlightFields;
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#hasId()
*/
@Override
public String getIndex() {
return delegate.getIndex();
}
@Override
public boolean hasId() {
return delegate.hasId();
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#getId()
*/
@Override
public String getId() {
return delegate.getId();
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#setId(java.lang.String)
*/
@Override
public void setId(String id) {
delegate.setId(id);
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#hasVersion()
*/
@Override
public boolean hasVersion() {
return delegate.hasVersion();
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#getVersion()
*/
@Override
public long getVersion() {
return delegate.getVersion();
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#setVersion(long)
*/
@Override
public void setVersion(long version) {
delegate.setVersion(version);
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#hasSeqNo()
*/
@Override
public boolean hasSeqNo() {
return delegate.hasSeqNo();
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#getSeqNo()
*/
@Override
public long getSeqNo() {
return delegate.getSeqNo();
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#setSeqNo(long)
*/
@Override
public void setSeqNo(long seqNo) {
delegate.setSeqNo(seqNo);
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#hasPrimaryTerm()
*/
@Override
public boolean hasPrimaryTerm() {
return delegate.hasPrimaryTerm();
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#getPrimaryTerm()
*/
@Override
public long getPrimaryTerm() {
return delegate.getPrimaryTerm();
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#setPrimaryTerm(long)
*/
@Override
public void setPrimaryTerm(long primaryTerm) {
delegate.setPrimaryTerm(primaryTerm);
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#get(java.lang.Object, java.lang.Class)
*/
@Override
@Nullable
public <T> T get(Object key, Class<T> type) {
return delegate.get(key, type);
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#toJson()
*/
@Override
public String toJson() {
return delegate.toJson();
}
/*
* (non-Javadoc)
* @see java.util.Map#size()
*/
@Override
public int size() {
return delegate.size();
}
/*
* (non-Javadoc)
* @see java.util.Map#isEmpty()
*/
@Override
public boolean isEmpty() {
return delegate.isEmpty();
}
/*
* (non-Javadoc)
* @see java.util.Map#containsKey(java.lang.Object)
*/
@Override
public boolean containsKey(Object key) {
return delegate.containsKey(key);
}
/*
* (non-Javadoc)
* @see java.util.Map#containsValue(java.lang.Object)
*/
@Override
public boolean containsValue(Object value) {
return delegate.containsValue(value);
}
/*
* (non-Javadoc)
* @see java.util.Map#get(java.lang.Object)
*/
@Override
public Object get(Object key) {
return delegate.get(key);
}
/*
* (non-Javadoc)
* @see java.util.Map#put(java.lang.Object, java.lang.Object)
*/
@Override
public Object put(String key, Object value) {
return delegate.put(key, value);
}
/*
* (non-Javadoc)
* @see java.util.Map#remove(java.lang.Object)
*/
@Override
public Object remove(Object key) {
return delegate.remove(key);
}
/*
* (non-Javadoc)
* @see java.util.Map#putAll(Map)
*/
@Override
public void putAll(Map<? extends String, ?> m) {
delegate.putAll(m);
}
/*
* (non-Javadoc)
* @see java.util.Map#clear()
*/
@Override
public void clear() {
delegate.clear();
}
/*
* (non-Javadoc)
* @see java.util.Map#keySet()
*/
@Override
public Set<String> keySet() {
return delegate.keySet();
}
/*
* (non-Javadoc)
* @see java.util.Map#values()
*/
@Override
public Collection<Object> values() {
return delegate.values();
}
/*
* (non-Javadoc)
* @see java.util.Map#entrySet()
*/
@Override
public Set<Entry<String, Object>> entrySet() {
return delegate.entrySet();
}
/*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object o) {
if (this == o) {
@ -815,37 +613,21 @@ public class DocumentAdapters {
return Float.compare(that.score, score) == 0 && delegate.equals(that.delegate);
}
/*
* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
return delegate.hashCode();
}
/*
* (non-Javadoc)
* @see java.util.Map#forEach(java.util.function.BiConsumer)
*/
@Override
public void forEach(BiConsumer<? super String, ? super Object> action) {
delegate.forEach(action);
}
/*
* (non-Javadoc)
* @see java.util.Map#remove(java.lang.Object, java.lang.Object)
*/
@Override
public boolean remove(Object key, Object value) {
return delegate.remove(key, value);
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {

View File

@ -40,6 +40,7 @@ class MapDocument implements Document {
private final LinkedHashMap<String, Object> documentAsMap;
private @Nullable String index;
private @Nullable String id;
private @Nullable Long version;
private @Nullable Long seqNo;
@ -53,6 +54,17 @@ class MapDocument implements Document {
this.documentAsMap = new LinkedHashMap<>(documentAsMap);
}
@Override
public void setIndex(@Nullable String index) {
this.index = index;
}
@Nullable
@Override
public String getIndex() {
return index;
}
/*
* (non-Javadoc)
* @see org.springframework.data.elasticsearch.core.document.Document#hasId()

View File

@ -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();

View File

@ -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

View File

@ -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);
}
}
}

View File

@ -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