summaryrefslogtreecommitdiff
path: root/core/src/test/java
diff options
context:
space:
mode:
authorolcbean <olcbean@yahoo.com>2017-06-29 11:35:28 +0200
committerChristoph Büscher <christoph@elastic.co>2017-06-29 11:35:28 +0200
commit3518e313b81564d2868c834111d716997dd86033 (patch)
tree1a33138bf135ee90a97dd7997334f8e6d1e316d2 /core/src/test/java
parentda59c178e2cd39ac141c8e738ad692b94813eecd (diff)
Unify the result interfaces from get and search in Java client (#25361)
As GetField and SearchHitField have the same members, they have been unified into DocumentField. Closes #16440
Diffstat (limited to 'core/src/test/java')
-rw-r--r--core/src/test/java/org/elasticsearch/action/get/GetResponseTests.java6
-rw-r--r--core/src/test/java/org/elasticsearch/action/search/ExpandSearchPhaseTests.java12
-rw-r--r--core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java8
-rw-r--r--core/src/test/java/org/elasticsearch/action/update/UpdateResponseTests.java8
-rw-r--r--core/src/test/java/org/elasticsearch/index/get/DocumentFieldTests.java (renamed from core/src/test/java/org/elasticsearch/index/get/GetFieldTests.java)48
-rw-r--r--core/src/test/java/org/elasticsearch/index/get/GetResultTests.java31
-rw-r--r--core/src/test/java/org/elasticsearch/search/SearchHitTests.java7
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/metrics/AbstractGeoTestCase.java5
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java8
-rw-r--r--core/src/test/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHitsTests.java4
-rw-r--r--core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java6
-rw-r--r--core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java11
12 files changed, 79 insertions, 75 deletions
diff --git a/core/src/test/java/org/elasticsearch/action/get/GetResponseTests.java b/core/src/test/java/org/elasticsearch/action/get/GetResponseTests.java
index aa753ef817..d607a473b9 100644
--- a/core/src/test/java/org/elasticsearch/action/get/GetResponseTests.java
+++ b/core/src/test/java/org/elasticsearch/action/get/GetResponseTests.java
@@ -24,10 +24,10 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.Tuple;
+import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
-import org.elasticsearch.index.get.GetField;
import org.elasticsearch.index.get.GetResult;
import org.elasticsearch.test.ESTestCase;
@@ -92,7 +92,7 @@ public class GetResponseTests extends ESTestCase {
public void testToXContent() {
{
GetResponse getResponse = new GetResponse(new GetResult("index", "type", "id", 1, true, new BytesArray("{ \"field1\" : " +
- "\"value1\", \"field2\":\"value2\"}"), Collections.singletonMap("field1", new GetField("field1",
+ "\"value1\", \"field2\":\"value2\"}"), Collections.singletonMap("field1", new DocumentField("field1",
Collections.singletonList("value1")))));
String output = Strings.toString(getResponse);
assertEquals("{\"_index\":\"index\",\"_type\":\"type\",\"_id\":\"id\",\"_version\":1,\"found\":true,\"_source\":{ \"field1\" " +
@@ -108,7 +108,7 @@ public class GetResponseTests extends ESTestCase {
public void testToString() {
GetResponse getResponse = new GetResponse(
new GetResult("index", "type", "id", 1, true, new BytesArray("{ \"field1\" : " + "\"value1\", \"field2\":\"value2\"}"),
- Collections.singletonMap("field1", new GetField("field1", Collections.singletonList("value1")))));
+ Collections.singletonMap("field1", new DocumentField("field1", Collections.singletonList("value1")))));
assertEquals("{\"_index\":\"index\",\"_type\":\"type\",\"_id\":\"id\",\"_version\":1,\"found\":true,\"_source\":{ \"field1\" "
+ ": \"value1\", \"field2\":\"value2\"},\"fields\":{\"field1\":[\"value1\"]}}", getResponse.toString());
}
diff --git a/core/src/test/java/org/elasticsearch/action/search/ExpandSearchPhaseTests.java b/core/src/test/java/org/elasticsearch/action/search/ExpandSearchPhaseTests.java
index fef4cff6a4..b27c7ec395 100644
--- a/core/src/test/java/org/elasticsearch/action/search/ExpandSearchPhaseTests.java
+++ b/core/src/test/java/org/elasticsearch/action/search/ExpandSearchPhaseTests.java
@@ -20,6 +20,7 @@
package org.elasticsearch.action.search;
import org.elasticsearch.action.ActionListener;
+import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.index.query.BoolQueryBuilder;
@@ -27,7 +28,6 @@ import org.elasticsearch.index.query.InnerHitBuilder;
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.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.collapse.CollapseBuilder;
@@ -105,7 +105,7 @@ public class ExpandSearchPhaseTests extends ESTestCase {
};
SearchHits hits = new SearchHits(new SearchHit[]{new SearchHit(1, "ID", new Text("type"),
- Collections.singletonMap("someField", new SearchHitField("someField", Collections.singletonList(collapseValue))))},
+ Collections.singletonMap("someField", new DocumentField("someField", Collections.singletonList(collapseValue))))},
1, 1.0F);
InternalSearchResponse internalSearchResponse = new InternalSearchResponse(hits, null, null, null, false, null, 1);
AtomicReference<SearchResponse> reference = new AtomicReference<>();
@@ -160,9 +160,9 @@ public class ExpandSearchPhaseTests extends ESTestCase {
};
SearchHits hits = new SearchHits(new SearchHit[]{new SearchHit(1, "ID", new Text("type"),
- Collections.singletonMap("someField", new SearchHitField("someField", Collections.singletonList(collapseValue)))),
+ Collections.singletonMap("someField", new DocumentField("someField", Collections.singletonList(collapseValue)))),
new SearchHit(2, "ID2", new Text("type"),
- Collections.singletonMap("someField", new SearchHitField("someField", Collections.singletonList(collapseValue))))}, 1,
+ Collections.singletonMap("someField", new DocumentField("someField", Collections.singletonList(collapseValue))))}, 1,
1.0F);
InternalSearchResponse internalSearchResponse = new InternalSearchResponse(hits, null, null, null, false, null, 1);
AtomicReference<SearchResponse> reference = new AtomicReference<>();
@@ -194,9 +194,9 @@ public class ExpandSearchPhaseTests extends ESTestCase {
};
SearchHits hits = new SearchHits(new SearchHit[]{new SearchHit(1, "ID", new Text("type"),
- Collections.singletonMap("someField", new SearchHitField("someField", Collections.singletonList(null)))),
+ Collections.singletonMap("someField", new DocumentField("someField", Collections.singletonList(null)))),
new SearchHit(2, "ID2", new Text("type"),
- Collections.singletonMap("someField", new SearchHitField("someField", Collections.singletonList(null))))}, 1, 1.0F);
+ Collections.singletonMap("someField", new DocumentField("someField", Collections.singletonList(null))))}, 1, 1.0F);
InternalSearchResponse internalSearchResponse = new InternalSearchResponse(hits, null, null, null, false, null, 1);
AtomicReference<SearchResponse> reference = new AtomicReference<>();
ExpandSearchPhase phase = new ExpandSearchPhase(mockSearchPhaseContext, internalSearchResponse, r ->
diff --git a/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java b/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java
index 4f50e70dde..7049d0fa9e 100644
--- a/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java
+++ b/core/src/test/java/org/elasticsearch/action/update/UpdateRequestTests.java
@@ -26,6 +26,7 @@ import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.support.replication.ReplicationRequest;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
+import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.io.stream.Streamable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
@@ -37,7 +38,6 @@ import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.env.Environment;
import org.elasticsearch.index.VersionType;
-import org.elasticsearch.index.get.GetField;
import org.elasticsearch.index.get.GetResult;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.script.MockScriptEngine;
@@ -532,9 +532,9 @@ public class UpdateRequestTests extends ESTestCase {
assertNull(UpdateHelper.calculateRouting(getResult, indexRequest));
assertNull(UpdateHelper.calculateParent(getResult, indexRequest));
- Map<String, GetField> fields = new HashMap<>();
- fields.put("_parent", new GetField("_parent", Collections.singletonList("parent1")));
- fields.put("_routing", new GetField("_routing", Collections.singletonList("routing1")));
+ Map<String, DocumentField> fields = new HashMap<>();
+ fields.put("_parent", new DocumentField("_parent", Collections.singletonList("parent1")));
+ fields.put("_routing", new DocumentField("_routing", Collections.singletonList("routing1")));
// Doc exists and has the parent and routing fields
getResult = new GetResult("test", "type", "1", 0, true, null, fields);
diff --git a/core/src/test/java/org/elasticsearch/action/update/UpdateResponseTests.java b/core/src/test/java/org/elasticsearch/action/update/UpdateResponseTests.java
index 7423cc5adf..c8d63f7373 100644
--- a/core/src/test/java/org/elasticsearch/action/update/UpdateResponseTests.java
+++ b/core/src/test/java/org/elasticsearch/action/update/UpdateResponseTests.java
@@ -26,10 +26,10 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.Tuple;
+import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
-import org.elasticsearch.index.get.GetField;
import org.elasticsearch.index.get.GetResult;
import org.elasticsearch.index.get.GetResultTests;
import org.elasticsearch.index.shard.ShardId;
@@ -68,9 +68,9 @@ public class UpdateResponseTests extends ESTestCase {
}
{
BytesReference source = new BytesArray("{\"title\":\"Book title\",\"isbn\":\"ABC-123\"}");
- Map<String, GetField> fields = new HashMap<>();
- fields.put("title", new GetField("title", Collections.singletonList("Book title")));
- fields.put("isbn", new GetField("isbn", Collections.singletonList("ABC-123")));
+ Map<String, DocumentField> fields = new HashMap<>();
+ fields.put("title", new DocumentField("title", Collections.singletonList("Book title")));
+ fields.put("isbn", new DocumentField("isbn", Collections.singletonList("ABC-123")));
UpdateResponse updateResponse = new UpdateResponse(new ReplicationResponse.ShardInfo(3, 2),
new ShardId("books", "books_uuid", 2), "book", "1", 7, 17, 2, UPDATED);
diff --git a/core/src/test/java/org/elasticsearch/index/get/GetFieldTests.java b/core/src/test/java/org/elasticsearch/index/get/DocumentFieldTests.java
index 62cd45508d..0b8549e005 100644
--- a/core/src/test/java/org/elasticsearch/index/get/GetFieldTests.java
+++ b/core/src/test/java/org/elasticsearch/index/get/DocumentFieldTests.java
@@ -22,6 +22,7 @@ package org.elasticsearch.index.get;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.Tuple;
+import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentType;
@@ -41,62 +42,63 @@ import static org.elasticsearch.common.xcontent.XContentHelper.toXContent;
import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent;
-public class GetFieldTests extends ESTestCase {
+public class DocumentFieldTests extends ESTestCase {
public void testToXContent() {
- GetField getField = new GetField("field", Arrays.asList("value1", "value2"));
- String output = Strings.toString(getField);
+ DocumentField documentField = new DocumentField("field", Arrays.asList("value1", "value2"));
+ String output = Strings.toString(documentField);
assertEquals("{\"field\":[\"value1\",\"value2\"]}", output);
}
public void testEqualsAndHashcode() {
- checkEqualsAndHashCode(randomGetField(XContentType.JSON).v1(), GetFieldTests::copyGetField, GetFieldTests::mutateGetField);
+ checkEqualsAndHashCode(randomDocumentField(XContentType.JSON).v1(), DocumentFieldTests::copyDocumentField,
+ DocumentFieldTests::mutateDocumentField);
}
public void testToAndFromXContent() throws Exception {
XContentType xContentType = randomFrom(XContentType.values());
- Tuple<GetField, GetField> tuple = randomGetField(xContentType);
- GetField getField = tuple.v1();
- GetField expectedGetField = tuple.v2();
+ Tuple<DocumentField, DocumentField> tuple = randomDocumentField(xContentType);
+ DocumentField documentField = tuple.v1();
+ DocumentField expectedDocumentField = tuple.v2();
boolean humanReadable = randomBoolean();
- BytesReference originalBytes = toShuffledXContent(getField, xContentType, ToXContent.EMPTY_PARAMS, humanReadable);
+ BytesReference originalBytes = toShuffledXContent(documentField, xContentType, ToXContent.EMPTY_PARAMS, humanReadable);
//test that we can parse what we print out
- GetField parsedGetField;
+ DocumentField parsedDocumentField;
try (XContentParser parser = createParser(xContentType.xContent(), originalBytes)) {
//we need to move to the next token, the start object one that we manually added is not expected
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken());
- parsedGetField = GetField.fromXContent(parser);
+ parsedDocumentField = DocumentField.fromXContent(parser);
assertEquals(XContentParser.Token.END_ARRAY, parser.currentToken());
assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
assertNull(parser.nextToken());
}
- assertEquals(expectedGetField, parsedGetField);
- BytesReference finalBytes = toXContent(parsedGetField, xContentType, humanReadable);
+ assertEquals(expectedDocumentField, parsedDocumentField);
+ BytesReference finalBytes = toXContent(parsedDocumentField, xContentType, humanReadable);
assertToXContentEquivalent(originalBytes, finalBytes, xContentType);
}
- private static GetField copyGetField(GetField getField) {
- return new GetField(getField.getName(), getField.getValues());
+ private static DocumentField copyDocumentField(DocumentField documentField) {
+ return new DocumentField(documentField.getName(), documentField.getValues());
}
- private static GetField mutateGetField(GetField getField) {
- List<Supplier<GetField>> mutations = new ArrayList<>();
- mutations.add(() -> new GetField(randomUnicodeOfCodepointLength(15), getField.getValues()));
- mutations.add(() -> new GetField(getField.getName(), randomGetField(XContentType.JSON).v1().getValues()));
+ private static DocumentField mutateDocumentField(DocumentField documentField) {
+ List<Supplier<DocumentField>> mutations = new ArrayList<>();
+ mutations.add(() -> new DocumentField(randomUnicodeOfCodepointLength(15), documentField.getValues()));
+ mutations.add(() -> new DocumentField(documentField.getName(), randomDocumentField(XContentType.JSON).v1().getValues()));
return randomFrom(mutations).get();
}
- public static Tuple<GetField, GetField> randomGetField(XContentType xContentType) {
+ public static Tuple<DocumentField, DocumentField> randomDocumentField(XContentType xContentType) {
if (randomBoolean()) {
String fieldName = randomFrom(ParentFieldMapper.NAME, RoutingFieldMapper.NAME, UidFieldMapper.NAME);
- GetField getField = new GetField(fieldName, Collections.singletonList(randomAlphaOfLengthBetween(3, 10)));
- return Tuple.tuple(getField, getField);
+ DocumentField documentField = new DocumentField(fieldName, Collections.singletonList(randomAlphaOfLengthBetween(3, 10)));
+ return Tuple.tuple(documentField, documentField);
}
String fieldName = randomAlphaOfLengthBetween(3, 10);
Tuple<List<Object>, List<Object>> tuple = RandomObjects.randomStoredFieldValues(random(), xContentType);
- GetField input = new GetField(fieldName, tuple.v1());
- GetField expected = new GetField(fieldName, tuple.v2());
+ DocumentField input = new DocumentField(fieldName, tuple.v1());
+ DocumentField expected = new DocumentField(fieldName, tuple.v2());
return Tuple.tuple(input, expected);
}
}
diff --git a/core/src/test/java/org/elasticsearch/index/get/GetResultTests.java b/core/src/test/java/org/elasticsearch/index/get/GetResultTests.java
index c23a648aff..a38d183299 100644
--- a/core/src/test/java/org/elasticsearch/index/get/GetResultTests.java
+++ b/core/src/test/java/org/elasticsearch/index/get/GetResultTests.java
@@ -23,6 +23,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.Tuple;
+import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.common.xcontent.XContentParser;
@@ -42,7 +43,7 @@ import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static org.elasticsearch.common.xcontent.XContentHelper.toXContent;
import static org.elasticsearch.common.xcontent.XContentParserUtils.ensureExpectedToken;
-import static org.elasticsearch.index.get.GetFieldTests.randomGetField;
+import static org.elasticsearch.index.get.DocumentFieldTests.randomDocumentField;
import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertToXContentEquivalent;
@@ -72,7 +73,7 @@ public class GetResultTests extends ESTestCase {
public void testToXContent() throws IOException {
{
GetResult getResult = new GetResult("index", "type", "id", 1, true, new BytesArray("{ \"field1\" : " +
- "\"value1\", \"field2\":\"value2\"}"), singletonMap("field1", new GetField("field1",
+ "\"value1\", \"field2\":\"value2\"}"), singletonMap("field1", new DocumentField("field1",
singletonList("value1"))));
String output = Strings.toString(getResult);
assertEquals("{\"_index\":\"index\",\"_type\":\"type\",\"_id\":\"id\",\"_version\":1,\"found\":true,\"_source\":{ \"field1\" " +
@@ -115,9 +116,9 @@ public class GetResultTests extends ESTestCase {
}
public void testToXContentEmbedded() throws IOException {
- Map<String, GetField> fields = new HashMap<>();
- fields.put("foo", new GetField("foo", singletonList("bar")));
- fields.put("baz", new GetField("baz", Arrays.asList("baz_0", "baz_1")));
+ Map<String, DocumentField> fields = new HashMap<>();
+ fields.put("foo", new DocumentField("foo", singletonList("bar")));
+ fields.put("baz", new DocumentField("baz", Arrays.asList("baz_0", "baz_1")));
GetResult getResult = new GetResult("index", "type", "id", 2, true,
new BytesArray("{\"foo\":\"bar\",\"baz\":[\"baz_0\",\"baz_1\"]}"), fields);
@@ -169,7 +170,7 @@ public class GetResultTests extends ESTestCase {
mutations.add(() -> new GetResult(getResult.getIndex(), getResult.getType(), getResult.getId(), getResult.getVersion(),
getResult.isExists(), RandomObjects.randomSource(random()), getResult.getFields()));
mutations.add(() -> new GetResult(getResult.getIndex(), getResult.getType(), getResult.getId(), getResult.getVersion(),
- getResult.isExists(), getResult.internalSourceRef(), randomGetFields(XContentType.JSON).v1()));
+ getResult.isExists(), getResult.internalSourceRef(), randomDocumentFields(XContentType.JSON).v1()));
return randomFrom(mutations).get();
}
@@ -180,8 +181,8 @@ public class GetResultTests extends ESTestCase {
final long version;
final boolean exists;
BytesReference source = null;
- Map<String, GetField> fields = null;
- Map<String, GetField> expectedFields = null;
+ Map<String, DocumentField> fields = null;
+ Map<String, DocumentField> expectedFields = null;
if (frequently()) {
version = randomNonNegativeLong();
exists = true;
@@ -189,7 +190,7 @@ public class GetResultTests extends ESTestCase {
source = RandomObjects.randomSource(random());
}
if (randomBoolean()) {
- Tuple<Map<String, GetField>, Map<String, GetField>> tuple = randomGetFields(xContentType);
+ Tuple<Map<String, DocumentField>, Map<String, DocumentField>> tuple = randomDocumentFields(xContentType);
fields = tuple.v1();
expectedFields = tuple.v2();
}
@@ -202,14 +203,14 @@ public class GetResultTests extends ESTestCase {
return Tuple.tuple(getResult, expectedGetResult);
}
- private static Tuple<Map<String, GetField>,Map<String, GetField>> randomGetFields(XContentType xContentType) {
+ private static Tuple<Map<String, DocumentField>,Map<String, DocumentField>> randomDocumentFields(XContentType xContentType) {
int numFields = randomIntBetween(2, 10);
- Map<String, GetField> fields = new HashMap<>(numFields);
- Map<String, GetField> expectedFields = new HashMap<>(numFields);
+ Map<String, DocumentField> fields = new HashMap<>(numFields);
+ Map<String, DocumentField> expectedFields = new HashMap<>(numFields);
for (int i = 0; i < numFields; i++) {
- Tuple<GetField, GetField> tuple = randomGetField(xContentType);
- GetField getField = tuple.v1();
- GetField expectedGetField = tuple.v2();
+ Tuple<DocumentField, DocumentField> tuple = randomDocumentField(xContentType);
+ DocumentField getField = tuple.v1();
+ DocumentField expectedGetField = tuple.v2();
fields.put(getField.getName(), getField);
expectedFields.put(expectedGetField.getName(), expectedGetField);
}
diff --git a/core/src/test/java/org/elasticsearch/search/SearchHitTests.java b/core/src/test/java/org/elasticsearch/search/SearchHitTests.java
index 5c7f11875e..fb5ecb3811 100644
--- a/core/src/test/java/org/elasticsearch/search/SearchHitTests.java
+++ b/core/src/test/java/org/elasticsearch/search/SearchHitTests.java
@@ -24,6 +24,7 @@ import org.elasticsearch.action.OriginalIndices;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.Tuple;
+import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.InputStreamStreamInput;
import org.elasticsearch.common.text.Text;
@@ -70,7 +71,7 @@ public class SearchHitTests extends ESTestCase {
if (randomBoolean()) {
nestedIdentity = NestedIdentityTests.createTestItem(randomIntBetween(0, 2));
}
- Map<String, SearchHitField> fields = new HashMap<>();
+ Map<String, DocumentField> fields = new HashMap<>();
if (randomBoolean()) {
int size = randomIntBetween(0, 10);
for (int i = 0; i < size; i++) {
@@ -78,10 +79,10 @@ public class SearchHitTests extends ESTestCase {
XContentType.JSON);
if (randomBoolean()) {
String metaField = randomFrom(META_FIELDS);
- fields.put(metaField, new SearchHitField(metaField, values.v1()));
+ fields.put(metaField, new DocumentField(metaField, values.v1()));
} else {
String fieldName = randomAlphaOfLengthBetween(5, 10);
- fields.put(fieldName, new SearchHitField(fieldName, values.v1()));
+ fields.put(fieldName, new DocumentField(fieldName, values.v1()));
}
}
}
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AbstractGeoTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AbstractGeoTestCase.java
index ec91db0c8f..51d54e5dcb 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AbstractGeoTestCase.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/AbstractGeoTestCase.java
@@ -23,8 +23,10 @@ import com.carrotsearch.hppc.ObjectIntHashMap;
import com.carrotsearch.hppc.ObjectIntMap;
import com.carrotsearch.hppc.ObjectObjectHashMap;
import com.carrotsearch.hppc.ObjectObjectMap;
+
import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
+import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.geo.GeoHashUtils;
import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.settings.Settings;
@@ -32,7 +34,6 @@ import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.search.SearchHit;
-import org.elasticsearch.search.SearchHitField;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.test.ESIntegTestCase;
@@ -189,7 +190,7 @@ public abstract class AbstractGeoTestCase extends ESIntegTestCase {
SearchHit searchHit = response.getHits().getAt(i);
assertThat("Hit " + i + " with id: " + searchHit.getId(), searchHit.getIndex(), equalTo("high_card_idx"));
assertThat("Hit " + i + " with id: " + searchHit.getId(), searchHit.getType(), equalTo("type"));
- SearchHitField hitField = searchHit.field(NUMBER_FIELD_NAME);
+ DocumentField hitField = searchHit.field(NUMBER_FIELD_NAME);
assertThat("Hit " + i + " has wrong number of values", hitField.getValues().size(), equalTo(1));
Long value = hitField.getValue();
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java
index a90960c2ec..2287d2ba98 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/TopHitsIT.java
@@ -25,6 +25,7 @@ import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.search.SearchPhaseExecutionException;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
+import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
@@ -36,9 +37,9 @@ import org.elasticsearch.script.MockScriptPlugin;
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.aggregations.Aggregator.SubAggCollectionMode;
+import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.aggregations.InternalAggregation;
import org.elasticsearch.search.aggregations.bucket.global.Global;
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
@@ -47,7 +48,6 @@ import org.elasticsearch.search.aggregations.bucket.terms.Terms;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregatorFactory.ExecutionMode;
import org.elasticsearch.search.aggregations.metrics.max.Max;
import org.elasticsearch.search.aggregations.metrics.tophits.TopHits;
-import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightField;
import org.elasticsearch.search.rescore.RescoreBuilder;
@@ -615,7 +615,7 @@ public class TopHitsIT extends ESIntegTestCase {
assertThat(hit.getMatchedQueries()[0], equalTo("test"));
- SearchHitField field = hit.field("field1");
+ DocumentField field = hit.field("field1");
assertThat(field.getValue().toString(), equalTo("5"));
assertThat(hit.getSourceAsMap().get("text").toString(), equalTo("some text to entertain"));
@@ -893,7 +893,7 @@ public class TopHitsIT extends ESIntegTestCase {
assertThat(searchHit.getMatchedQueries(), arrayContaining("test"));
- SearchHitField field = searchHit.field("comments.user");
+ DocumentField field = searchHit.field("comments.user");
assertThat(field.getValue().toString(), equalTo("a"));
field = searchHit.field("script");
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHitsTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHitsTests.java
index af4e0bac3e..cfec0d6aae 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHitsTests.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/tophits/InternalTopHitsTests.java
@@ -28,10 +28,10 @@ import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.TopFieldDocs;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.collect.Tuple;
+import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.search.SearchHit;
-import org.elasticsearch.search.SearchHitField;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.ParsedAggregation;
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
@@ -85,7 +85,7 @@ public class InternalTopHitsTests extends InternalAggregationTestCase<InternalTo
int docId = randomValueOtherThanMany(usedDocIds::contains, () -> between(0, IndexWriter.MAX_DOCS));
usedDocIds.add(docId);
- Map<String, SearchHitField> searchHitFields = new HashMap<>();
+ Map<String, DocumentField> searchHitFields = new HashMap<>();
if (testInstancesLookSortedByField) {
Object[] fields = new Object[testInstancesSortFields.length];
for (int f = 0; f < testInstancesSortFields.length; f++) {
diff --git a/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java b/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java
index 6c1d0877f7..0912236e01 100644
--- a/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java
+++ b/core/src/test/java/org/elasticsearch/search/fetch/FetchSubPhasePluginIT.java
@@ -27,6 +27,7 @@ import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.termvectors.TermVectorsRequest;
import org.elasticsearch.action.termvectors.TermVectorsResponse;
import org.elasticsearch.common.ParsingException;
+import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.logging.ESLoggerFactory;
@@ -36,7 +37,6 @@ import org.elasticsearch.index.termvectors.TermVectorsService;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.plugins.SearchPlugin;
import org.elasticsearch.search.SearchExtBuilder;
-import org.elasticsearch.search.SearchHitField;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.internal.SearchContext;
import org.elasticsearch.test.ESIntegTestCase;
@@ -129,9 +129,9 @@ public class FetchSubPhasePluginIT extends ESIntegTestCase {
if (hitContext.hit().fieldsOrNull() == null) {
hitContext.hit().fields(new HashMap<>());
}
- SearchHitField hitField = hitContext.hit().getFields().get(NAME);
+ DocumentField hitField = hitContext.hit().getFields().get(NAME);
if (hitField == null) {
- hitField = new SearchHitField(NAME, new ArrayList<>(1));
+ hitField = new DocumentField(NAME, new ArrayList<>(1));
hitContext.hit().getFields().put(NAME, hitField);
}
TermVectorsRequest termVectorsRequest = new TermVectorsRequest(context.indexShard().shardId().getIndex().getName(),
diff --git a/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java b/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java
index f333548795..5ae2687585 100644
--- a/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java
+++ b/core/src/test/java/org/elasticsearch/search/fields/SearchFieldsIT.java
@@ -26,8 +26,8 @@ import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.MapBuilder;
+import org.elasticsearch.common.document.DocumentField;
import org.elasticsearch.common.joda.Joda;
-import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
@@ -39,7 +39,6 @@ import org.elasticsearch.script.MockScriptPlugin;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.search.SearchHit;
-import org.elasticsearch.search.SearchHitField;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.lookup.FieldLookup;
import org.elasticsearch.search.sort.SortOrder;
@@ -487,7 +486,7 @@ public class SearchFieldsIT extends ESIntegTestCase {
assertNoFailures(response);
- SearchHitField fieldObj = response.getHits().getAt(0).field("test_script_1");
+ DocumentField fieldObj = response.getHits().getAt(0).field("test_script_1");
assertThat(fieldObj, notNullValue());
List<?> fieldValues = fieldObj.getValues();
assertThat(fieldValues, hasSize(1));
@@ -715,7 +714,7 @@ public class SearchFieldsIT extends ESIntegTestCase {
SearchResponse searchResponse = client().prepareSearch("test").setTypes("type").setSource(
new SearchSourceBuilder().query(QueryBuilders.matchAllQuery()).fieldDataField("test_field")).get();
assertHitCount(searchResponse, 1);
- Map<String,SearchHitField> fields = searchResponse.getHits().getHits()[0].getFields();
+ Map<String, DocumentField> fields = searchResponse.getHits().getHits()[0].getFields();
assertThat(fields.get("test_field").getValue(), equalTo("foobar"));
}
@@ -854,7 +853,7 @@ public class SearchFieldsIT extends ESIntegTestCase {
assertSearchResponse(resp);
for (SearchHit hit : resp.getHits().getHits()) {
final int id = Integer.parseInt(hit.getId());
- Map<String, SearchHitField> fields = hit.getFields();
+ Map<String, DocumentField> fields = hit.getFields();
assertThat(fields.get("s").getValues(), equalTo(Collections.<Object> singletonList(Integer.toString(id))));
assertThat(fields.get("l").getValues(), equalTo(Collections.<Object> singletonList((long) id)));
assertThat(fields.get("d").getValues(), equalTo(Collections.<Object> singletonList((double) id)));
@@ -876,7 +875,7 @@ public class SearchFieldsIT extends ESIntegTestCase {
assertSearchResponse(response);
assertHitCount(response, 1);
- Map<String, SearchHitField> fields = response.getHits().getAt(0).getFields();
+ Map<String, DocumentField> fields = response.getHits().getAt(0).getFields();
assertThat(fields.get("field1"), nullValue());
assertThat(fields.get("_routing").isMetadataField(), equalTo(true));