diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/enrich/PutPolicyRequest.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/enrich/PutPolicyRequest.java index 0eb902dfe46..8ffc039517a 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/enrich/PutPolicyRequest.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/enrich/PutPolicyRequest.java @@ -78,7 +78,10 @@ public final class PutPolicyRequest implements Validatable, ToXContentObject { return query; } - public void setQuery(BytesReference query) { + // package private for testing only + void setQuery(BytesReference query) { + assert query == null || XContentHelper.xContentType(query) == XContentType.JSON : + "Only accepts JSON encoded query but received [" + Strings.toString(query) + "]"; this.query = query; } @@ -106,7 +109,7 @@ public final class PutPolicyRequest implements Validatable, ToXContentObject { { builder.field(NamedPolicy.INDICES_FIELD.getPreferredName(), indices); if (query != null) { - builder.field(NamedPolicy.QUERY_FIELD.getPreferredName(), asMap(query, builder.contentType())); + builder.field(NamedPolicy.QUERY_FIELD.getPreferredName(), asMap(query, XContentType.JSON)); } builder.field(NamedPolicy.MATCH_FIELD_FIELD.getPreferredName(), matchField); builder.field(NamedPolicy.ENRICH_FIELDS_FIELD.getPreferredName(), enrichFields); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/enrich/PutPolicyRequestTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/enrich/PutPolicyRequestTests.java index a0138949490..7edb50309a8 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/enrich/PutPolicyRequestTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/enrich/PutPolicyRequestTests.java @@ -94,7 +94,7 @@ public class PutPolicyRequestTests extends AbstractRequestTestCase