mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-13 07:32:11 +00:00
Make SearchType in query nullable, set to null in NativeQuery with knnQuery.
Original Pull Request #2570 Closes #2569
This commit is contained in:
parent
6edd3cf1fe
commit
36e3b93ea9
@ -22,6 +22,7 @@ import co.elastic.clients.elasticsearch._types.Conflicts;
|
||||
import co.elastic.clients.elasticsearch._types.FieldValue;
|
||||
import co.elastic.clients.elasticsearch._types.InlineScript;
|
||||
import co.elastic.clients.elasticsearch._types.OpType;
|
||||
import co.elastic.clients.elasticsearch._types.SearchType;
|
||||
import co.elastic.clients.elasticsearch._types.SortOptions;
|
||||
import co.elastic.clients.elasticsearch._types.SortOrder;
|
||||
import co.elastic.clients.elasticsearch._types.VersionType;
|
||||
@ -1153,9 +1154,12 @@ class RequestConverter {
|
||||
var query = param.query();
|
||||
mrb.searches(sb -> sb //
|
||||
.header(h -> {
|
||||
var searchType = (query instanceof NativeQuery nativeQuery && nativeQuery.getKnnQuery() != null) ? null
|
||||
: searchType(query.getSearchType());
|
||||
|
||||
h //
|
||||
.index(Arrays.asList(param.index().getIndexNames())) //
|
||||
.searchType(searchType(query.getSearchType())) //
|
||||
.searchType(searchType) //
|
||||
.requestCache(query.getRequestCache()) //
|
||||
;
|
||||
|
||||
@ -1256,8 +1260,8 @@ class RequestConverter {
|
||||
query.getScriptedFields().forEach(scriptedField -> bb.scriptFields(scriptedField.getFieldName(),
|
||||
sf -> sf.script(getScript(scriptedField.getScriptData()))));
|
||||
|
||||
if (query instanceof NativeQuery) {
|
||||
prepareNativeSearch((NativeQuery) query, bb);
|
||||
if (query instanceof NativeQuery nativeQuery) {
|
||||
prepareNativeSearch(nativeQuery, bb);
|
||||
}
|
||||
return bb;
|
||||
} //
|
||||
@ -1279,12 +1283,15 @@ class RequestConverter {
|
||||
|
||||
ElasticsearchPersistentEntity<?> persistentEntity = getPersistentEntity(clazz);
|
||||
|
||||
var searchType = (query instanceof NativeQuery nativeQuery && nativeQuery.getKnnQuery() != null) ? null
|
||||
: searchType(query.getSearchType());
|
||||
|
||||
builder //
|
||||
.version(true) //
|
||||
.trackScores(query.getTrackScores()) //
|
||||
.allowNoIndices(query.getAllowNoIndices()) //
|
||||
.source(getSourceConfig(query)) //
|
||||
.searchType(searchType(query.getSearchType())) //
|
||||
.searchType(searchType) //
|
||||
.timeout(timeStringMs(query.getTimeout())) //
|
||||
.requestCache(query.getRequestCache()) //
|
||||
;
|
||||
@ -1361,8 +1368,8 @@ class RequestConverter {
|
||||
query.getScriptedFields().forEach(scriptedField -> builder.scriptFields(scriptedField.getFieldName(),
|
||||
sf -> sf.script(getScript(scriptedField.getScriptData()))));
|
||||
|
||||
if (query instanceof NativeQuery) {
|
||||
prepareNativeSearch((NativeQuery) query, builder);
|
||||
if (query instanceof NativeQuery nativeQuery) {
|
||||
prepareNativeSearch(nativeQuery, builder);
|
||||
}
|
||||
|
||||
if (query.getTrackTotalHits() != null) {
|
||||
|
@ -58,7 +58,7 @@ public class BaseQuery implements Query {
|
||||
protected float minScore;
|
||||
@Nullable protected Collection<String> ids;
|
||||
@Nullable protected String route;
|
||||
protected SearchType searchType = SearchType.QUERY_THEN_FETCH;
|
||||
@Nullable protected SearchType searchType = SearchType.QUERY_THEN_FETCH;
|
||||
@Nullable protected IndicesOptions indicesOptions;
|
||||
protected boolean trackScores;
|
||||
@Nullable protected String preference;
|
||||
@ -278,10 +278,11 @@ public class BaseQuery implements Query {
|
||||
this.route = route;
|
||||
}
|
||||
|
||||
public void setSearchType(SearchType searchType) {
|
||||
public void setSearchType(@Nullable SearchType searchType) {
|
||||
this.searchType = searchType;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public SearchType getSearchType() {
|
||||
return searchType;
|
||||
|
@ -46,7 +46,7 @@ public abstract class BaseQueryBuilder<Q extends BaseQuery, SELF extends BaseQue
|
||||
private float minScore;
|
||||
private final Collection<String> ids = new ArrayList<>();
|
||||
@Nullable private String route;
|
||||
private Query.SearchType searchType = Query.SearchType.QUERY_THEN_FETCH;
|
||||
@Nullable private Query.SearchType searchType = Query.SearchType.QUERY_THEN_FETCH;
|
||||
@Nullable private IndicesOptions indicesOptions;
|
||||
private boolean trackScores;
|
||||
@Nullable private String preference;
|
||||
@ -140,6 +140,7 @@ public abstract class BaseQueryBuilder<Q extends BaseQuery, SELF extends BaseQue
|
||||
return indicesBoost;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Query.SearchType getSearchType() {
|
||||
return searchType;
|
||||
}
|
||||
@ -250,11 +251,11 @@ public abstract class BaseQueryBuilder<Q extends BaseQuery, SELF extends BaseQue
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Ids for a multi-get request run with this query. Not used in any other searches.
|
||||
*
|
||||
* @param ids list of id values
|
||||
*/
|
||||
/**
|
||||
* Set Ids for a multi-get request run with this query. Not used in any other searches.
|
||||
*
|
||||
* @param ids list of id values
|
||||
*/
|
||||
public SELF withIds(String... ids) {
|
||||
|
||||
this.ids.clear();
|
||||
@ -262,11 +263,11 @@ public abstract class BaseQueryBuilder<Q extends BaseQuery, SELF extends BaseQue
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Ids for a multi-get request run with this query. Not used in any other searches.
|
||||
*
|
||||
* @param ids list of id values
|
||||
*/
|
||||
/**
|
||||
* Set Ids for a multi-get request run with this query. Not used in any other searches.
|
||||
*
|
||||
* @param ids list of id values
|
||||
*/
|
||||
public SELF withIds(Collection<String> ids) {
|
||||
|
||||
Assert.notNull(ids, "ids must not be null");
|
||||
@ -342,7 +343,7 @@ public abstract class BaseQueryBuilder<Q extends BaseQuery, SELF extends BaseQue
|
||||
return self();
|
||||
}
|
||||
|
||||
public SELF withSearchType(Query.SearchType searchType) {
|
||||
public SELF withSearchType(@Nullable Query.SearchType searchType) {
|
||||
this.searchType = searchType;
|
||||
return self();
|
||||
}
|
||||
@ -382,12 +383,12 @@ public abstract class BaseQueryBuilder<Q extends BaseQuery, SELF extends BaseQue
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Ids with routing values for a multi-get request run with this query. Not used in any other searches.
|
||||
*
|
||||
* @param idsWithRouting list of id values, must not be {@literal null}
|
||||
* @since 4.3
|
||||
*/
|
||||
/**
|
||||
* Set Ids with routing values for a multi-get request run with this query. Not used in any other searches.
|
||||
*
|
||||
* @param idsWithRouting list of id values, must not be {@literal null}
|
||||
* @since 4.3
|
||||
*/
|
||||
public SELF withIdsWithRouting(List<Query.IdWithRouting> idsWithRouting) {
|
||||
|
||||
Assert.notNull(idsWithRouting, "idsWithRouting must not be null");
|
||||
|
@ -221,6 +221,7 @@ public interface Query {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
SearchType getSearchType();
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user