|
@@ -40,8 +40,8 @@ public class WatcherSearchTemplateRequest implements ToXContentObject {
|
|
|
private final SearchType searchType;
|
|
|
private final IndicesOptions indicesOptions;
|
|
|
private final Script template;
|
|
|
-
|
|
|
private final BytesReference searchSource;
|
|
|
+ private boolean restTotalHitsAsInt;
|
|
|
|
|
|
public WatcherSearchTemplateRequest(String[] indices, String[] types, SearchType searchType, IndicesOptions indicesOptions,
|
|
|
BytesReference searchSource) {
|
|
@@ -72,6 +72,7 @@ public class WatcherSearchTemplateRequest implements ToXContentObject {
|
|
|
this.indicesOptions = original.indicesOptions;
|
|
|
this.searchSource = source;
|
|
|
this.template = original.template;
|
|
|
+ this.restTotalHitsAsInt = original.restTotalHitsAsInt;
|
|
|
}
|
|
|
|
|
|
private WatcherSearchTemplateRequest(String[] indices, String[] types, SearchType searchType, IndicesOptions indicesOptions,
|
|
@@ -105,6 +106,19 @@ public class WatcherSearchTemplateRequest implements ToXContentObject {
|
|
|
return indicesOptions;
|
|
|
}
|
|
|
|
|
|
+ public boolean isRestTotalHitsAsint() {
|
|
|
+ return restTotalHitsAsInt;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Indicates whether the total hits in the response should be
|
|
|
+ * serialized as number (<code>true</code>) or as an object (<code>false</code>).
|
|
|
+ * Defaults to false.
|
|
|
+ */
|
|
|
+ public void setRestTotalHitsAsInt(boolean value) {
|
|
|
+ this.restTotalHitsAsInt = restTotalHitsAsInt;
|
|
|
+ }
|
|
|
+
|
|
|
public BytesReference getSearchSource() {
|
|
|
return searchSource;
|
|
|
}
|
|
@@ -129,6 +143,9 @@ public class WatcherSearchTemplateRequest implements ToXContentObject {
|
|
|
if (types != null) {
|
|
|
builder.array(TYPES_FIELD.getPreferredName(), types);
|
|
|
}
|
|
|
+ if (restTotalHitsAsInt) {
|
|
|
+ builder.field(REST_TOTAL_HITS_AS_INT_FIELD.getPreferredName(), restTotalHitsAsInt);
|
|
|
+ }
|
|
|
if (searchSource != null && searchSource.length() > 0) {
|
|
|
try (InputStream stream = searchSource.streamInput()) {
|
|
|
builder.rawField(BODY_FIELD.getPreferredName(), stream);
|
|
@@ -167,6 +184,7 @@ public class WatcherSearchTemplateRequest implements ToXContentObject {
|
|
|
IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS;
|
|
|
BytesReference searchSource = null;
|
|
|
Script template = null;
|
|
|
+ boolean totalHitsAsInt = false;
|
|
|
|
|
|
XContentParser.Token token;
|
|
|
String currentFieldName = null;
|
|
@@ -263,10 +281,19 @@ public class WatcherSearchTemplateRequest implements ToXContentObject {
|
|
|
types.addAll(Arrays.asList(Strings.delimitedListToStringArray(typesStr, ",", " \t")));
|
|
|
} else if (SEARCH_TYPE_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
|
|
|
searchType = SearchType.fromString(parser.text().toLowerCase(Locale.ROOT));
|
|
|
+ } else if (REST_TOTAL_HITS_AS_INT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
|
|
|
+ totalHitsAsInt = parser.booleanValue();
|
|
|
} else {
|
|
|
throw new ElasticsearchParseException("could not read search request. unexpected string field [" +
|
|
|
currentFieldName + "]");
|
|
|
}
|
|
|
+ } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
|
|
|
+ if (REST_TOTAL_HITS_AS_INT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
|
|
|
+ totalHitsAsInt = parser.booleanValue();
|
|
|
+ } else {
|
|
|
+ throw new ElasticsearchParseException("could not read search request. unexpected boolean field [" +
|
|
|
+ currentFieldName + "]");
|
|
|
+ }
|
|
|
} else {
|
|
|
throw new ElasticsearchParseException("could not read search request. unexpected token [" + token + "]");
|
|
|
}
|
|
@@ -276,8 +303,10 @@ public class WatcherSearchTemplateRequest implements ToXContentObject {
|
|
|
searchSource = BytesArray.EMPTY;
|
|
|
}
|
|
|
|
|
|
- return new WatcherSearchTemplateRequest(indices.toArray(new String[0]), types.toArray(new String[0]), searchType,
|
|
|
- indicesOptions, searchSource, template);
|
|
|
+ WatcherSearchTemplateRequest request = new WatcherSearchTemplateRequest(indices.toArray(new String[0]),
|
|
|
+ types.toArray(new String[0]), searchType, indicesOptions, searchSource, template);
|
|
|
+ request.setRestTotalHitsAsInt(totalHitsAsInt);
|
|
|
+ return request;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -291,13 +320,14 @@ public class WatcherSearchTemplateRequest implements ToXContentObject {
|
|
|
Objects.equals(searchType, other.searchType) &&
|
|
|
Objects.equals(indicesOptions, other.indicesOptions) &&
|
|
|
Objects.equals(searchSource, other.searchSource) &&
|
|
|
- Objects.equals(template, other.template);
|
|
|
+ Objects.equals(template, other.template) &&
|
|
|
+ Objects.equals(restTotalHitsAsInt, other.restTotalHitsAsInt);
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int hashCode() {
|
|
|
- return Objects.hash(indices, types, searchType, indicesOptions, searchSource, template);
|
|
|
+ return Objects.hash(indices, types, searchType, indicesOptions, searchSource, template, restTotalHitsAsInt);
|
|
|
}
|
|
|
|
|
|
private static final ParseField INDICES_FIELD = new ParseField("indices");
|
|
@@ -309,6 +339,7 @@ public class WatcherSearchTemplateRequest implements ToXContentObject {
|
|
|
private static final ParseField IGNORE_UNAVAILABLE_FIELD = new ParseField("ignore_unavailable");
|
|
|
private static final ParseField ALLOW_NO_INDICES_FIELD = new ParseField("allow_no_indices");
|
|
|
private static final ParseField TEMPLATE_FIELD = new ParseField("template");
|
|
|
+ private static final ParseField REST_TOTAL_HITS_AS_INT_FIELD = new ParseField("rest_total_hits_as_int");
|
|
|
|
|
|
public static final IndicesOptions DEFAULT_INDICES_OPTIONS = IndicesOptions.lenientExpandOpen();
|
|
|
}
|