diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RatedDocumentKey.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RatedDocumentKey.java index c10bc3f0ce0..3efcc7e16a4 100644 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RatedDocumentKey.java +++ b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RatedDocumentKey.java @@ -21,18 +21,20 @@ package org.elasticsearch.index.rankeval; import org.elasticsearch.action.support.ToXContentToBytes; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.FromXContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; import java.util.Objects; -public class RatedDocumentKey extends ToXContentToBytes implements Writeable { +public class RatedDocumentKey extends ToXContentToBytes implements Writeable, FromXContentBuilder { public static final ParseField DOC_ID_FIELD = new ParseField("doc_id"); public static final ParseField TYPE_FIELD = new ParseField("type"); public static final ParseField INDEX_FIELD = new ParseField("index"); @@ -103,7 +105,18 @@ public class RatedDocumentKey extends ToXContentToBytes implements Writeable { out.writeString(type); out.writeString(docId); } - + + @Override + public RatedDocumentKey fromXContent(XContentParser parser, ParseFieldMatcher matcher) throws IOException { + return RatedDocumentKey.fromXContent(parser, new ParseFieldMatcherSupplier() { + + @Override + public ParseFieldMatcher getParseFieldMatcher() { + return matcher; + } + }); + } + public static RatedDocumentKey fromXContent(XContentParser parser, ParseFieldMatcherSupplier context) throws IOException { return PARSER.apply(parser, context); } diff --git a/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RatedDocumentKeyTests.java b/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RatedDocumentKeyTests.java new file mode 100644 index 00000000000..1ec1bbbcc06 --- /dev/null +++ b/modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RatedDocumentKeyTests.java @@ -0,0 +1,34 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.index.rankeval; + +import java.io.IOException; + +public class RatedDocumentKeyTests extends XContentRoundtripTestCase { + + public void testXContentRoundtrip() throws IOException { + String index = randomAsciiOfLengthBetween(0, 10); + String type = randomAsciiOfLengthBetween(0, 10); + String docId = randomAsciiOfLengthBetween(0, 10); + + RatedDocumentKey testItem = new RatedDocumentKey(index, type, docId); + roundtrip(testItem); + } +}