Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package co.elastic.clients.elasticsearch._types;

import co.elastic.clients.elasticsearch.core.SearchRequest;
import co.elastic.clients.elasticsearch.core.search.SearchRequestBody;
import co.elastic.clients.json.JsonpDeserializable;
import co.elastic.clients.json.JsonpDeserializer;
Expand Down Expand Up @@ -163,6 +164,24 @@ public ObjectBuilder<ScriptSource> scriptTemplate(SearchRequestBody v) {
return this;
}

public final ObjectBuilder<ScriptSource> scriptTemplate(SearchRequest value) {
this._kind = Kind.ScriptTemplate;
SearchRequestBody body = SearchRequestBody.of(srb -> srb.aggregations(value.aggregations())
.collapse(value.collapse()).explain(value.explain()).ext(value.ext()).from(value.from())
.highlight(value.highlight()).trackTotalHits(value.trackTotalHits())
.indicesBoost(value.indicesBoost()).docvalueFields(value.docvalueFields()).knn(value.knn())
.rank(value.rank()).minScore(value.minScore()).postFilter(value.postFilter())
.profile(value.profile()).query(value.query()).rescore(value.rescore()).retriever(value.retriever())
.scriptFields(value.scriptFields()).searchAfter(value.searchAfter()).size(value.size())
.slice(value.slice()).sort(value.sort()).source(value.source()).fields(value.fields())
.suggest(value.suggest()).terminateAfter(value.terminateAfter()).timeout(value.timeout())
.trackScores(value.trackScores()).version(value.version())
.seqNoPrimaryTerm(value.seqNoPrimaryTerm()).storedFields(value.storedFields()).pit(value.pit())
.runtimeMappings(value.runtimeMappings()).stats(value.stats()));
this._value = body;
return this;
}

public ObjectBuilder<ScriptSource> scriptTemplate(
Function<SearchRequestBody.Builder, ObjectBuilder<SearchRequestBody>> fn) {
return this.scriptTemplate(fn.apply(new SearchRequestBody.Builder()).build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package co.elastic.clients.elasticsearch.core.msearch;

import co.elastic.clients.elasticsearch.core.SearchRequest;
import co.elastic.clients.elasticsearch.core.search.SearchRequestBody;
import co.elastic.clients.json.JsonpDeserializable;
import co.elastic.clients.json.JsonpDeserializer;
Expand Down Expand Up @@ -163,6 +164,23 @@ public final Builder body(Function<SearchRequestBody.Builder, ObjectBuilder<Sear
return this.body(fn.apply(new SearchRequestBody.Builder()).build());
}

public final Builder body(SearchRequest value) {
SearchRequestBody body = SearchRequestBody.of(srb -> srb.aggregations(value.aggregations())
.collapse(value.collapse()).explain(value.explain()).ext(value.ext()).from(value.from())
.highlight(value.highlight()).trackTotalHits(value.trackTotalHits())
.indicesBoost(value.indicesBoost()).docvalueFields(value.docvalueFields()).knn(value.knn())
.rank(value.rank()).minScore(value.minScore()).postFilter(value.postFilter())
.profile(value.profile()).query(value.query()).rescore(value.rescore()).retriever(value.retriever())
.scriptFields(value.scriptFields()).searchAfter(value.searchAfter()).size(value.size())
.slice(value.slice()).sort(value.sort()).source(value.source()).fields(value.fields())
.suggest(value.suggest()).terminateAfter(value.terminateAfter()).timeout(value.timeout())
.trackScores(value.trackScores()).version(value.version())
.seqNoPrimaryTerm(value.seqNoPrimaryTerm()).storedFields(value.storedFields()).pit(value.pit())
.runtimeMappings(value.runtimeMappings()).stats(value.stats()));
this.body = body;
return this;
}

/**
* Builds a {@link RequestItem}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.FieldSort;
import co.elastic.clients.elasticsearch._types.FieldValue;
import co.elastic.clients.elasticsearch._types.ScriptSource;
import co.elastic.clients.elasticsearch._types.aggregations.TopMetrics;
import co.elastic.clients.elasticsearch._types.query_dsl.MatchAllQuery;
import co.elastic.clients.elasticsearch.core.MsearchRequest;
import co.elastic.clients.elasticsearch.core.SearchRequest;
import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.testkit.ModelTestCase;
Expand Down Expand Up @@ -81,13 +83,68 @@ public void arrayOverloads() {
}

@Test
@Disabled("just need to compile")
@Disabled("just needs to compile")
public void voidClassTDocumentOverload() throws IOException {
// no need for a complete instance of the client,
// nor testing anything, just checking this compiles
// nor testing anything, just checking that this compiles
ElasticsearchClient client = ElasticsearchClient.of(e -> e.host("http://localhost:9200"));

SearchResponse<Void> resp = client.search(s -> s,Void.class);
SearchResponse<Void> respDefault = client.search(s -> s);
}

@Test
public void searchRequestBodyOverloads() throws IOException {

// Normal search request
SearchRequest searchRequest = SearchRequest.of(b -> b
.size(10)
.from(10)
.query(q -> q
.matchAll(m -> m)
)
);

// Msearch compatibility
MsearchRequest msearchRequestStandard = MsearchRequest.of(ms -> ms
.searches(s -> s
.header(h -> h.index("index"))
.body(b -> b
.size(10)
.from(10)
.query(q -> q
.matchAll(m -> m)
)
)
)
);

MsearchRequest msearchRequestOverload = MsearchRequest.of(ms -> ms
.searches(s -> s
.header(h -> h.index("index"))
.body(searchRequest)
)
);

// Assert both variants result in the same serialization
assertEquals(msearchRequestStandard.toString(), msearchRequestOverload.toString());

// Script source compatibility
ScriptSource scriptSourceStandard = ScriptSource.of(s -> s
.scriptTemplate(t -> t
.size(10)
.from(10)
.query(q -> q
.matchAll(m -> m)
)
)
);

ScriptSource scriptSourceOverload = ScriptSource.of(s -> s
.scriptTemplate(searchRequest)
);

// Assert both variants result in the same serialization
assertEquals(scriptSourceStandard.toString(), scriptSourceOverload.toString());
}
}