mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-08 13:12:10 +00:00
Add search extension plugins parameters to NativeQuery.
Original Pull Request #2307 Closes #2150
This commit is contained in:
parent
b4fe01d09b
commit
1396f53fde
@ -20,6 +20,7 @@ import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||
import co.elastic.clients.elasticsearch.core.search.FieldCollapse;
|
||||
import co.elastic.clients.elasticsearch.core.search.Suggester;
|
||||
import co.elastic.clients.json.JsonData;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -49,6 +50,8 @@ public class NativeQuery extends BaseQuery {
|
||||
private List<ScriptedField> scriptedFields = Collections.emptyList();
|
||||
private List<SortOptions> sortOptions = Collections.emptyList();
|
||||
|
||||
private Map<String, JsonData> searchExtensions = Collections.emptyMap();
|
||||
|
||||
public NativeQuery(NativeQueryBuilder builder) {
|
||||
super(builder);
|
||||
this.query = builder.getQuery();
|
||||
@ -58,6 +61,7 @@ public class NativeQuery extends BaseQuery {
|
||||
this.fieldCollapse = builder.getFieldCollapse();
|
||||
this.scriptedFields = builder.getScriptedFields();
|
||||
this.sortOptions = builder.getSortOptions();
|
||||
this.searchExtensions = builder.getSearchExtensions();
|
||||
}
|
||||
|
||||
public NativeQuery(@Nullable Query query) {
|
||||
@ -99,4 +103,8 @@ public class NativeQuery extends BaseQuery {
|
||||
public List<SortOptions> getSortOptions() {
|
||||
return sortOptions;
|
||||
}
|
||||
|
||||
public Map<String, JsonData> getSearchExtensions() {
|
||||
return searchExtensions;
|
||||
}
|
||||
}
|
||||
|
@ -20,11 +20,11 @@ import co.elastic.clients.elasticsearch._types.aggregations.Aggregation;
|
||||
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
||||
import co.elastic.clients.elasticsearch.core.search.FieldCollapse;
|
||||
import co.elastic.clients.elasticsearch.core.search.Suggester;
|
||||
import co.elastic.clients.json.JsonData;
|
||||
import co.elastic.clients.util.ObjectBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -49,9 +49,9 @@ public class NativeQueryBuilder extends BaseQueryBuilder<NativeQuery, NativeQuer
|
||||
@Nullable private FieldCollapse fieldCollapse;
|
||||
private final List<ScriptedField> scriptedFields = new ArrayList<>();
|
||||
private List<SortOptions> sortOptions = new ArrayList<>();
|
||||
private Map<String, JsonData> searchExtensions = new LinkedHashMap<>();
|
||||
|
||||
public NativeQueryBuilder() {
|
||||
}
|
||||
public NativeQueryBuilder() {}
|
||||
|
||||
@Nullable
|
||||
public Query getQuery() {
|
||||
@ -85,6 +85,10 @@ public class NativeQueryBuilder extends BaseQueryBuilder<NativeQuery, NativeQuer
|
||||
return sortOptions;
|
||||
}
|
||||
|
||||
public Map<String, JsonData> getSearchExtensions() {
|
||||
return this.searchExtensions;
|
||||
}
|
||||
|
||||
public NativeQueryBuilder withQuery(Query query) {
|
||||
|
||||
Assert.notNull(query, "query must not be null");
|
||||
@ -167,6 +171,23 @@ public class NativeQueryBuilder extends BaseQueryBuilder<NativeQuery, NativeQuer
|
||||
return this;
|
||||
}
|
||||
|
||||
public NativeQueryBuilder withSearchExtension(String key, JsonData value) {
|
||||
|
||||
Assert.notNull(key, "key must not be null");
|
||||
Assert.notNull(value, "value must not be null");
|
||||
|
||||
searchExtensions.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NativeQueryBuilder withSearchExtensions(Map<String, JsonData> searchExtensions) {
|
||||
|
||||
Assert.notNull(searchExtensions, "searchExtensions must not be null");
|
||||
|
||||
searchExtensions.putAll(searchExtensions);
|
||||
return this;
|
||||
}
|
||||
|
||||
public NativeQuery build() {
|
||||
return new NativeQuery(this);
|
||||
}
|
||||
|
@ -1398,7 +1398,9 @@ class RequestConverter {
|
||||
builder.aggregations(query.getAggregations());
|
||||
}
|
||||
|
||||
// todo #2150 searchExt, currently not supported by the new client
|
||||
if (!isEmpty(query.getSearchExtensions())) {
|
||||
builder.ext(query.getSearchExtensions());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("DuplicatedCode")
|
||||
@ -1416,7 +1418,9 @@ class RequestConverter {
|
||||
builder.aggregations(query.getAggregations());
|
||||
}
|
||||
|
||||
// todo #2150 searchExt, currently not supported by the new client
|
||||
if (!isEmpty(query.getSearchExtensions())) {
|
||||
builder.ext(query.getSearchExtensions());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
Loading…
x
Reference in New Issue
Block a user