Elasticsearch-net: Unable to use From \ Size variables on SearchTemplates

Created on 25 Apr 2017  路  4Comments  路  Source: elastic/elasticsearch-net

NEST/Elasticsearch.Net version: 5.3.1

Elasticsearch version: 5.3.1

Description of the problem including expected versus actual behavior:
When creating a search template, we cant use pagination as From() and Size() only takes nullable integers - so specifying "{{my_from_var}}" is impossible.

Most helpful comment

Well then, as for a workaround for anyone else trying to do this:

var jsonSearchTemplate = _client.Serializer.SerializeToString(searchRequest);
var customObject = JObject.Parse(jsonSearchTemplate);
customObject.Add("from", "{{from}}{{^from}}0{{/from}}");
customObject.Add("size", "{{size}}{{^size}}10{{/size}}");
jsonSearchTemplate = _client.Serializer.SerializeToString(customObject);

And add size and from as parameters when querying by template.

All 4 comments

Hi @Cnordbo

We won't support this out of the box, the SearchRequest related types are for Search() only. You may be able to utilize them for SearchTemplate but you might run into cases like you just found out.

Well then, as for a workaround for anyone else trying to do this:

var jsonSearchTemplate = _client.Serializer.SerializeToString(searchRequest);
var customObject = JObject.Parse(jsonSearchTemplate);
customObject.Add("from", "{{from}}{{^from}}0{{/from}}");
customObject.Add("size", "{{size}}{{^size}}10{{/size}}");
jsonSearchTemplate = _client.Serializer.SerializeToString(customObject);

And add size and from as parameters when querying by template.

@Cnordbo 馃憤 for posting workaround

@Cnordbo good workaround!

I've been using this to set size and from as params on a search template. Especially when using searchTemplate requests with the elasticsearch javascript SDK, since size and from aren't support on there as well.

Was this page helpful?
0 / 5 - 0 ratings