From 3ff5ee3f4731caf92e3770c2fc5a703f2efd26b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Thu, 29 Jun 2017 11:36:20 +0200 Subject: [PATCH] Adapting to merging GetField and SearchHitField to DocumentField (elastic/x-pack-elasticsearch#1860) Follow up to changes in https://github.com/elastic/elasticsearch/pull/25361 Original commit: elastic/x-pack-elasticsearch@5b1ca009f6376605c1f105daa14fe289f559e330 --- .../ml/datafeed/extractor/scroll/ExtractedField.java | 4 ++-- .../extractor/scroll/ScrollDataExtractorTests.java | 10 +++++----- .../xpack/ml/job/persistence/JobProviderTests.java | 8 ++++---- .../elasticsearch/xpack/ml/test/SearchHitBuilder.java | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/datafeed/extractor/scroll/ExtractedField.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/datafeed/extractor/scroll/ExtractedField.java index 7dcf38d2828..c2d866563d6 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/datafeed/extractor/scroll/ExtractedField.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/datafeed/extractor/scroll/ExtractedField.java @@ -5,8 +5,8 @@ */ package org.elasticsearch.xpack.ml.datafeed.extractor.scroll; +import org.elasticsearch.common.document.DocumentField; import org.elasticsearch.search.SearchHit; -import org.elasticsearch.search.SearchHitField; import org.joda.time.base.BaseDateTime; import java.util.List; @@ -82,7 +82,7 @@ abstract class ExtractedField { @Override public Object[] value(SearchHit hit) { - SearchHitField keyValue = hit.field(name); + DocumentField keyValue = hit.field(name); if (keyValue != null) { List values = keyValue.getValues(); return values.toArray(new Object[values.size()]); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/datafeed/extractor/scroll/ScrollDataExtractorTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/datafeed/extractor/scroll/ScrollDataExtractorTests.java index 389dff72d90..c7a47f4eb16 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/datafeed/extractor/scroll/ScrollDataExtractorTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/datafeed/extractor/scroll/ScrollDataExtractorTests.java @@ -10,13 +10,13 @@ import org.elasticsearch.action.search.SearchRequestBuilder; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.ShardSearchFailure; import org.elasticsearch.client.Client; +import org.elasticsearch.common.document.DocumentField; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptType; import org.elasticsearch.search.SearchHit; -import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.test.ESTestCase; @@ -453,10 +453,10 @@ public class ScrollDataExtractorTests extends ESTestCase { List hits = new ArrayList<>(); for (int i = 0; i < timestamps.size(); i++) { SearchHit hit = new SearchHit(randomInt()); - Map fields = new HashMap<>(); - fields.put(extractedFields.timeField(), new SearchHitField("time", Arrays.asList(timestamps.get(i)))); - fields.put("field_1", new SearchHitField("field_1", Arrays.asList(field1Values.get(i)))); - fields.put("field_2", new SearchHitField("field_2", Arrays.asList(field2Values.get(i)))); + Map fields = new HashMap<>(); + fields.put(extractedFields.timeField(), new DocumentField("time", Arrays.asList(timestamps.get(i)))); + fields.put("field_1", new DocumentField("field_1", Arrays.asList(field1Values.get(i)))); + fields.put("field_2", new DocumentField("field_2", Arrays.asList(field2Values.get(i)))); hit.fields(fields); hits.add(hit); } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobProviderTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobProviderTests.java index 27bb8e6dda5..7ec183a7407 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobProviderTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/job/persistence/JobProviderTests.java @@ -27,6 +27,7 @@ import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.collect.ImmutableOpenMap; +import org.elasticsearch.common.document.DocumentField; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.text.Text; import org.elasticsearch.common.xcontent.XContentFactory; @@ -34,7 +35,6 @@ import org.elasticsearch.index.Index; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; -import org.elasticsearch.search.SearchHitField; import org.elasticsearch.search.SearchHits; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.ml.MlMetadata; @@ -880,9 +880,9 @@ public class JobProviderTests extends ESTestCase { for (Map map : source) { Map _source = new HashMap<>(map); - Map fields = new HashMap<>(); - fields.put("field_1", new SearchHitField("field_1", Collections.singletonList("foo"))); - fields.put("field_2", new SearchHitField("field_2", Collections.singletonList("foo"))); + Map fields = new HashMap<>(); + fields.put("field_1", new DocumentField("field_1", Collections.singletonList("foo"))); + fields.put("field_2", new DocumentField("field_2", Collections.singletonList("foo"))); SearchHit hit = new SearchHit(123, String.valueOf(map.hashCode()), new Text("foo"), fields) .sourceRef(XContentFactory.jsonBuilder().map(_source).bytes()); diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/test/SearchHitBuilder.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/test/SearchHitBuilder.java index 0a1b8931f1d..af4be50a134 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/test/SearchHitBuilder.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/test/SearchHitBuilder.java @@ -6,8 +6,8 @@ package org.elasticsearch.xpack.ml.test; import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.document.DocumentField; import org.elasticsearch.search.SearchHit; -import org.elasticsearch.search.SearchHitField; import java.util.Arrays; import java.util.HashMap; @@ -20,7 +20,7 @@ import java.util.Map; public class SearchHitBuilder { private final SearchHit hit; - private final Map fields; + private final Map fields; public SearchHitBuilder(int docId) { hit = new SearchHit(docId); @@ -32,7 +32,7 @@ public class SearchHitBuilder { } public SearchHitBuilder addField(String name, List values) { - fields.put(name, new SearchHitField(name, values)); + fields.put(name, new DocumentField(name, values)); return this; }