Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove _type from SearchHit #46942

Merged
merged 12 commits into from
Sep 23, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.elasticsearch.rest.action.document.RestBulkAction;
import org.elasticsearch.search.SearchHit;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;

import java.io.IOException;
import java.util.Arrays;
Expand All @@ -56,9 +55,7 @@
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.fieldFromSource;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasIndex;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasProperty;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasType;
import static org.hamcrest.Matchers.both;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.either;
Expand Down Expand Up @@ -360,7 +357,6 @@ public void testGlobalParametersAndBulkProcessor() throws Exception {
Iterable<SearchHit> hits = searchAll(new SearchRequest("test").routing("routing"));

assertThat(hits, everyItem(hasProperty(fieldFromSource("fieldNameXYZ"), equalTo("valueXYZ"))));
assertThat(hits, everyItem(Matchers.allOf(hasIndex("test"), hasType(globalType))));
assertThat(hits, containsInAnyOrder(expectedIds(numDocs)));
}

Expand Down Expand Up @@ -391,7 +387,6 @@ public void testGlobalParametersAndBulkProcessor() throws Exception {
Iterable<SearchHit> hits = searchAll(new SearchRequest("test").routing("routing"));

assertThat(hits, everyItem(hasProperty(fieldFromSource("fieldNameXYZ"), equalTo("valueXYZ"))));
assertThat(hits, everyItem(Matchers.allOf(hasIndex("test"), hasType(localType))));
assertThat(hits, containsInAnyOrder(expectedIds(numDocs)));
}
}
Expand Down Expand Up @@ -422,7 +417,6 @@ public void testGlobalParametersAndBulkProcessor() throws Exception {
Iterable<SearchHit> hits = searchAll(new SearchRequest("test").routing("routing"));

assertThat(hits, everyItem(hasProperty(fieldFromSource("fieldNameXYZ"), equalTo("valueXYZ"))));
assertThat(hits, everyItem(Matchers.allOf(hasIndex("test"), hasType(customType))));
assertThat(hits, containsInAnyOrder(expectedIds(numDocs)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasIndex;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasProperty;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasType;
import static org.hamcrest.Matchers.both;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.emptyIterable;
Expand Down Expand Up @@ -138,36 +137,6 @@ public void testIndexGlobalAndPerRequest() throws IOException {
.and(hasIndex("global_index"))));
}

public void testGlobalType() throws IOException {
BulkRequest request = new BulkRequest(null, "global_type");
request.add(new IndexRequest("index").id("1")
.source(XContentType.JSON, "field", "bulk1"));
request.add(new IndexRequest("index").id("2")
.source(XContentType.JSON, "field", "bulk2"));

bulkWithTypes(request);

Iterable<SearchHit> hits = searchAll("index");
assertThat(hits, everyItem(hasType("global_type")));
}

public void testTypeGlobalAndPerRequest() throws IOException {
BulkRequest request = new BulkRequest(null, "global_type");
request.add(new IndexRequest("index1", "local_type", "1")
.source(XContentType.JSON, "field", "bulk1"));
request.add(new IndexRequest("index2").id("2") // will take global type
.source(XContentType.JSON, "field", "bulk2"));

bulkWithTypes(request);

Iterable<SearchHit> hits = searchAll("index1", "index2");
assertThat(hits, containsInAnyOrder(
both(hasId("1"))
.and(hasType("local_type")),
both(hasId("2"))
.and(hasType("global_type"))));
}

public void testGlobalRouting() throws IOException {
createIndexWithMultipleShards("index");
BulkRequest request = new BulkRequest((String) null);
Expand All @@ -177,7 +146,7 @@ public void testGlobalRouting() throws IOException {
.source(XContentType.JSON, "field", "bulk1"));
request.routing("1");
bulk(request);

Iterable<SearchHit> emptyHits = searchAll(new SearchRequest("index").routing("xxx"));
assertThat(emptyHits, is(emptyIterable()));

Expand All @@ -199,7 +168,7 @@ public void testMixLocalAndGlobalRouting() throws IOException {
Iterable<SearchHit> hits = searchAll(new SearchRequest("index").routing("globalRouting", "localRouting"));
assertThat(hits, containsInAnyOrder(hasId("1"), hasId("2")));
}

public void testGlobalIndexNoTypes() throws IOException {
BulkRequest request = new BulkRequest("global_index");
request.add(new IndexRequest().id("1")
Expand All @@ -211,20 +180,20 @@ public void testGlobalIndexNoTypes() throws IOException {

Iterable<SearchHit> hits = searchAll("global_index");
assertThat(hits, everyItem(hasIndex("global_index")));
}
}

private BulkResponse bulkWithTypes(BulkRequest request) throws IOException {
BulkResponse bulkResponse = execute(request, highLevelClient()::bulk, highLevelClient()::bulkAsync,
BulkResponse bulkResponse = execute(request, highLevelClient()::bulk, highLevelClient()::bulkAsync,
expectWarnings(RestBulkAction.TYPES_DEPRECATION_MESSAGE));
assertFalse(bulkResponse.hasFailures());
return bulkResponse;
}

private BulkResponse bulk(BulkRequest request) throws IOException {
BulkResponse bulkResponse = execute(request, highLevelClient()::bulk, highLevelClient()::bulkAsync, RequestOptions.DEFAULT);
assertFalse(bulkResponse.hasFailures());
return bulkResponse;
}
}

@SuppressWarnings("unchecked")
private static <T> Function<SearchHit, T> fieldFromSource(String fieldName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ public void testSearchNoQuery() throws IOException {
assertEquals(5, searchResponse.getHits().getHits().length);
for (SearchHit searchHit : searchResponse.getHits().getHits()) {
assertEquals("index", searchHit.getIndex());
assertEquals("type", searchHit.getType());
assertThat(Integer.valueOf(searchHit.getId()), both(greaterThan(0)).and(lessThan(6)));
assertEquals(1.0f, searchHit.getScore(), 0);
assertEquals(-1L, searchHit.getVersion());
Expand All @@ -252,7 +251,6 @@ public void testSearchMatchQuery() throws IOException {
assertThat(searchResponse.getHits().getMaxScore(), greaterThan(0f));
SearchHit searchHit = searchResponse.getHits().getHits()[0];
assertEquals("index", searchHit.getIndex());
assertEquals("type", searchHit.getType());
assertEquals("1", searchHit.getId());
assertThat(searchHit.getScore(), greaterThan(0f));
assertEquals(-1L, searchHit.getVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ Possible response:
"hits": [
{
"_index": "sales",
"_type": "_doc",
"_id": "AVnNBmauCQpcRyxw6ChK",
"_source": {
"date": "2015/03/01 00:00:00",
Expand Down Expand Up @@ -117,7 +116,6 @@ Possible response:
"hits": [
{
"_index": "sales",
"_type": "_doc",
"_id": "AVnNBmauCQpcRyxw6ChL",
"_source": {
"date": "2015/03/01 00:00:00",
Expand Down Expand Up @@ -145,7 +143,6 @@ Possible response:
"hits": [
{
"_index": "sales",
"_type": "_doc",
"_id": "AVnNBmatCQpcRyxw6ChH",
"_source": {
"date": "2015/01/01 00:00:00",
Expand Down Expand Up @@ -331,7 +328,6 @@ Top hits response snippet with a nested hit, which resides in the first slot of
"hits": [
{
"_index": "sales",
"_type" : "_doc",
"_id": "1",
"_nested": {
"field": "comments", <1>
Expand Down Expand Up @@ -385,7 +381,6 @@ the second slow of the `nested_child_field` field:
"hits": [
{
"_index": "a",
"_type": "b",
"_id": "1",
"_score": 1,
"_nested" : {
Expand Down
1 change: 0 additions & 1 deletion docs/reference/aggregations/misc.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ In the response, the aggregations names will be changed to respectively `date_hi
"hits" : [
{
"_index": "twitter",
"_type": "_doc",
"_id": "0",
"_score": 1.0,
"_source": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ The output from the above is:
"hits": [
{
"_index": "my_index",
"_type": "_doc",
"_id": "1",
"_score": 0.2876821,
"_source": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,6 @@ GET my_index/_search
"hits": [
{
"_index": "my_index",
"_type": "_doc",
"_id": "1",
"_score": 0.5753642,
"_source": {
Expand Down
2 changes: 0 additions & 2 deletions docs/reference/getting-started.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -386,14 +386,12 @@ that match the search criteria:
"max_score" : null,
"hits" : [ {
"_index" : "bank",
"_type" : "_doc",
"_id" : "0",
"sort": [0],
"_score" : null,
"_source" : {"account_number":0,"balance":16623,"firstname":"Bradshaw","lastname":"Mckenzie","age":29,"gender":"F","address":"244 Columbus Place","employer":"Euron","email":"[email protected]","city":"Hobucken","state":"CO"}
}, {
"_index" : "bank",
"_type" : "_doc",
"_id" : "1",
"sort": [1],
"_score" : null,
Expand Down
4 changes: 0 additions & 4 deletions docs/reference/how-to/recipes/stemming.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ GET index/_search
"hits": [
{
"_index": "index",
"_type": "_doc",
"_id": "1",
"_score": 0.18232156,
"_source": {
Expand All @@ -97,7 +96,6 @@ GET index/_search
},
{
"_index": "index",
"_type": "_doc",
"_id": "2",
"_score": 0.18232156,
"_source": {
Expand Down Expand Up @@ -148,7 +146,6 @@ GET index/_search
"hits": [
{
"_index": "index",
"_type": "_doc",
"_id": "1",
"_score": 0.8025915,
"_source": {
Expand Down Expand Up @@ -207,7 +204,6 @@ GET index/_search
"hits": [
{
"_index": "index",
"_type": "_doc",
"_id": "1",
"_score": 0.8025915,
"_source": {
Expand Down
2 changes: 0 additions & 2 deletions docs/reference/index-modules/similarity.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ Which yields:
"_shard": "[index][0]",
"_node": "OzrdjxNtQGaqs4DmioFw9A",
"_index": "index",
"_type": "_doc",
"_id": "1",
"_score": 1.9508477,
"_source": {
Expand Down Expand Up @@ -433,7 +432,6 @@ GET /index/_search?explain=true
"_shard": "[index][0]",
"_node": "OzrdjxNtQGaqs4DmioFw9A",
"_index": "index",
"_type": "_doc",
"_id": "1",
"_score": 1.9508477,
"_source": {
Expand Down
1 change: 0 additions & 1 deletion docs/reference/ingest/processors/geoip.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ GET /my_ip_locations/_search
"hits" : [
{
"_index" : "my_ip_locations",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
Expand Down
2 changes: 0 additions & 2 deletions docs/reference/mapping/params/normalizer.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ both index and query time.
"hits": [
{
"_index": "index",
"_type": "_doc",
"_id": "1",
"_score": 0.47000363,
"_source": {
Expand All @@ -103,7 +102,6 @@ both index and query time.
},
{
"_index": "index",
"_type": "_doc",
"_id": "2",
"_score": 0.47000363,
"_source": {
Expand Down
4 changes: 0 additions & 4 deletions docs/reference/mapping/types/parent-join.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ Will return:
"hits": [
{
"_index": "my_index",
"_type": "_doc",
"_id": "1",
"_score": null,
"_source": {
Expand All @@ -192,7 +191,6 @@ Will return:
},
{
"_index": "my_index",
"_type": "_doc",
"_id": "2",
"_score": null,
"_source": {
Expand All @@ -205,7 +203,6 @@ Will return:
},
{
"_index": "my_index",
"_type": "_doc",
"_id": "3",
"_score": null,
"_routing": "1",
Expand All @@ -222,7 +219,6 @@ Will return:
},
{
"_index": "my_index",
"_type": "_doc",
"_id": "4",
"_score": null,
"_routing": "1",
Expand Down
3 changes: 0 additions & 3 deletions docs/reference/mapping/types/percolator.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ now returns matches from the new index:
"hits": [
{
"_index": "new_index", <1>
"_type": "_doc",
"_id": "1",
"_score": 0.13076457,
"_source": {
Expand Down Expand Up @@ -390,7 +389,6 @@ This results in a response like this:
"hits": [
{
"_index": "test_index",
"_type": "_doc",
"_id": "1",
"_score": 0.13076457,
"_source": {
Expand Down Expand Up @@ -547,7 +545,6 @@ GET /my_queries1/_search
"hits": [
{
"_index": "my_queries1",
"_type": "_doc",
"_id": "1",
"_score": 0.18864399,
"_source": {
Expand Down
2 changes: 0 additions & 2 deletions docs/reference/mapping/types/range.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ The result produced by the above query.
"hits" : [
{
"_index" : "range_index",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
Expand Down Expand Up @@ -156,7 +155,6 @@ This query produces a similar result:
"hits" : [
{
"_index" : "range_index",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
Expand Down
1 change: 0 additions & 1 deletion docs/reference/mapping/types/search-as-you-type.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ GET my_index/_search
"hits" : [
{
"_index" : "my_index",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.8630463,
"_source" : {
Expand Down
Loading