Skip to content

Commit

Permalink
[Remove] types from SearchHit and Explain API (#2205)
Browse files Browse the repository at this point in the history
* [Remove] types from SearchHit and Explain API

Removes type support from SearchHit and Explain API.

Signed-off-by: Nicholas Walter Knize <[email protected]>

* fix failing tests

Signed-off-by: Nicholas Walter Knize <[email protected]>

* move TYPES_DEPRECATION_MESSAGE from RestExplainAction to FullClusterRestartIT

Signed-off-by: Nicholas Walter Knize <[email protected]>

* fix FullClusterRestartIT

Signed-off-by: Nicholas Walter Knize <[email protected]>

* fix failing tests

Signed-off-by: Nicholas Walter Knize <[email protected]>

* fix testSoftDelete

Signed-off-by: Nicholas Walter Knize <[email protected]>
  • Loading branch information
nknize authored Feb 23, 2022
1 parent 1b571ec commit 3445bef
Show file tree
Hide file tree
Showing 83 changed files with 231 additions and 1,241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,7 @@ static Request count(CountRequest countRequest) throws IOException {
}

static Request explain(ExplainRequest explainRequest) throws IOException {
String endpoint = explainRequest.type().equals(MapperService.SINGLE_MAPPING_NAME)
? endpoint(explainRequest.index(), "_explain", explainRequest.id())
: endpoint(explainRequest.index(), explainRequest.type(), explainRequest.id(), "_explain");
String endpoint = endpoint(explainRequest.index(), "_explain", explainRequest.id());
Request request = new Request(HttpGet.METHOD_NAME, endpoint);

Params params = new Params();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1529,21 +1529,6 @@ public void testExplain() throws IOException {
assertToXContentBody(explainRequest, request.getEntity());
}

public void testExplainWithType() throws IOException {
String index = randomAlphaOfLengthBetween(3, 10);
String type = randomAlphaOfLengthBetween(3, 10);
String id = randomAlphaOfLengthBetween(3, 10);

ExplainRequest explainRequest = new ExplainRequest(index, type, id);
explainRequest.query(QueryBuilders.termQuery(randomAlphaOfLengthBetween(3, 10), randomAlphaOfLengthBetween(3, 10)));

Request request = RequestConverters.explain(explainRequest);
assertEquals(HttpGet.METHOD_NAME, request.getMethod());
assertEquals("/" + index + "/" + type + "/" + id + "/_explain", request.getEndpoint());

assertToXContentBody(explainRequest, request.getEntity());
}

public void testTermVectors() throws IOException {
String index = randomAlphaOfLengthBetween(3, 10);
String id = randomAlphaOfLengthBetween(3, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,6 @@ public void testExplain() throws IOException {
ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);

assertThat(explainResponse.getIndex(), equalTo("index1"));
assertThat(explainResponse.getType(), equalTo("_doc"));
assertThat(Integer.valueOf(explainResponse.getId()), equalTo(1));
assertTrue(explainResponse.isExists());
assertTrue(explainResponse.isMatch());
Expand All @@ -1149,7 +1148,6 @@ public void testExplain() throws IOException {
ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);

assertThat(explainResponse.getIndex(), equalTo("index1"));
assertThat(explainResponse.getType(), equalTo("_doc"));
assertThat(Integer.valueOf(explainResponse.getId()), equalTo(1));
assertTrue(explainResponse.isExists());
assertTrue(explainResponse.isMatch());
Expand All @@ -1164,7 +1162,6 @@ public void testExplain() throws IOException {
ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);

assertThat(explainResponse.getIndex(), equalTo("index1"));
assertThat(explainResponse.getType(), equalTo("_doc"));
assertThat(Integer.valueOf(explainResponse.getId()), equalTo(1));
assertTrue(explainResponse.isExists());
assertFalse(explainResponse.isMatch());
Expand All @@ -1180,7 +1177,6 @@ public void testExplain() throws IOException {
ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);

assertThat(explainResponse.getIndex(), equalTo("index1"));
assertThat(explainResponse.getType(), equalTo("_doc"));
assertThat(Integer.valueOf(explainResponse.getId()), equalTo(1));
assertTrue(explainResponse.isExists());
assertFalse(explainResponse.isMatch());
Expand Down Expand Up @@ -1212,7 +1208,6 @@ public void testExplainNonExistent() throws IOException {
ExplainResponse explainResponse = execute(explainRequest, highLevelClient()::explain, highLevelClient()::explainAsync);

assertThat(explainResponse.getIndex(), equalTo("index1"));
assertThat(explainResponse.getType(), equalTo("_doc"));
assertThat(explainResponse.getId(), equalTo("999"));
assertFalse(explainResponse.isExists());
assertFalse(explainResponse.isMatch());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.opensearch.action.search.SearchResponse;
import org.opensearch.action.search.ShardSearchFailure;
import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.text.Text;
import org.opensearch.common.xcontent.ToXContent;
import org.opensearch.common.xcontent.XContentBuilder;
import org.opensearch.common.xcontent.XContentFactory;
Expand Down Expand Up @@ -183,7 +182,7 @@ public void testSourceToXContent() throws IOException {
}

public void testSearchResponseToXContent() throws IOException {
SearchHit hit = new SearchHit(1, "id", new Text("type"), Collections.emptyMap(), Collections.emptyMap());
SearchHit hit = new SearchHit(1, "id", Collections.emptyMap(), Collections.emptyMap());
hit.score(2.0f);
SearchHit[] hits = new SearchHit[] { hit };

Expand Down Expand Up @@ -229,7 +228,6 @@ public void testSearchResponseToXContent() throws IOException {
.field("max_score", 1.5F)
.startArray("hits")
.startObject()
.field("_type", "type")
.field("_id", "id")
.field("_score", 2.0F)
.endObject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void testParentWithMultipleBuckets() throws Exception {
TopHits topHits = childrenBucket.getAggregations().get("top_comments");
logger.info("total_hits={}", topHits.getHits().getTotalHits().value);
for (SearchHit searchHit : topHits.getHits()) {
logger.info("hit= {} {} {}", searchHit.getSortValues()[0], searchHit.getType(), searchHit.getId());
logger.info("hit= {} {}", searchHit.getSortValues()[0], searchHit.getId());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ public void testExplainUsage() throws Exception {
assertHitCount(searchResponse, 1L);
assertThat(searchResponse.getHits().getAt(0).getExplanation().getDescription(), containsString("join value p1"));

ExplainResponse explainResponse = client().prepareExplain("test", "doc", parentId)
ExplainResponse explainResponse = client().prepareExplain("test", parentId)
.setQuery(hasChildQuery("child", termQuery("c_field", "1"), ScoreMode.Max))
.get();
assertThat(explainResponse.isExists(), equalTo(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ public void testSimpleParentChild() throws Exception {
assertThat(innerHits.getTotalHits().value, equalTo(2L));

assertThat(innerHits.getAt(0).getId(), equalTo("c1"));
assertThat(innerHits.getAt(0).getType(), equalTo("doc"));
assertThat(innerHits.getAt(1).getId(), equalTo("c2"));
assertThat(innerHits.getAt(1).getType(), equalTo("doc"));

final boolean seqNoAndTerm = randomBoolean();
response = client().prepareSearch("articles")
Expand All @@ -172,11 +170,8 @@ public void testSimpleParentChild() throws Exception {
assertThat(innerHits.getTotalHits().value, equalTo(3L));

assertThat(innerHits.getAt(0).getId(), equalTo("c4"));
assertThat(innerHits.getAt(0).getType(), equalTo("doc"));
assertThat(innerHits.getAt(1).getId(), equalTo("c5"));
assertThat(innerHits.getAt(1).getType(), equalTo("doc"));
assertThat(innerHits.getAt(2).getId(), equalTo("c6"));
assertThat(innerHits.getAt(2).getType(), equalTo("doc"));

if (seqNoAndTerm) {
assertThat(innerHits.getAt(0).getPrimaryTerm(), equalTo(1L));
Expand Down Expand Up @@ -301,15 +296,13 @@ public void testRandomParentChild() throws Exception {
int offset2 = 0;
for (int parent = 0; parent < numDocs; parent++) {
SearchHit searchHit = searchResponse.getHits().getAt(parent);
assertThat(searchHit.getType(), equalTo("doc"));
assertThat(searchHit.getId(), equalTo(String.format(Locale.ENGLISH, "p_%03d", parent)));
assertThat(searchHit.getShard(), notNullValue());

SearchHits inner = searchHit.getInnerHits().get("a");
assertThat(inner.getTotalHits().value, equalTo((long) child1InnerObjects[parent]));
for (int child = 0; child < child1InnerObjects[parent] && child < size; child++) {
SearchHit innerHit = inner.getAt(child);
assertThat(innerHit.getType(), equalTo("doc"));
String childId = String.format(Locale.ENGLISH, "c1_%04d", offset1 + child);
assertThat(innerHit.getId(), equalTo(childId));
assertThat(innerHit.getNestedIdentity(), nullValue());
Expand All @@ -320,7 +313,6 @@ public void testRandomParentChild() throws Exception {
assertThat(inner.getTotalHits().value, equalTo((long) child2InnerObjects[parent]));
for (int child = 0; child < child2InnerObjects[parent] && child < size; child++) {
SearchHit innerHit = inner.getAt(child);
assertThat(innerHit.getType(), equalTo("doc"));
String childId = String.format(Locale.ENGLISH, "c2_%04d", offset2 + child);
assertThat(innerHit.getId(), equalTo(childId));
assertThat(innerHit.getNestedIdentity(), nullValue());
Expand Down Expand Up @@ -376,16 +368,12 @@ public void testInnerHitsOnHasParent() throws Exception {

SearchHit searchHit = response.getHits().getAt(0);
assertThat(searchHit.getId(), equalTo("3"));
assertThat(searchHit.getType(), equalTo("doc"));
assertThat(searchHit.getInnerHits().get("question").getTotalHits().value, equalTo(1L));
assertThat(searchHit.getInnerHits().get("question").getAt(0).getType(), equalTo("doc"));
assertThat(searchHit.getInnerHits().get("question").getAt(0).getId(), equalTo("1"));

searchHit = response.getHits().getAt(1);
assertThat(searchHit.getId(), equalTo("4"));
assertThat(searchHit.getType(), equalTo("doc"));
assertThat(searchHit.getInnerHits().get("question").getTotalHits().value, equalTo(1L));
assertThat(searchHit.getInnerHits().get("question").getAt(0).getType(), equalTo("doc"));
assertThat(searchHit.getInnerHits().get("question").getAt(0).getId(), equalTo("2"));
}

Expand Down Expand Up @@ -430,12 +418,10 @@ public void testParentChildMultipleLayers() throws Exception {
SearchHits innerHits = response.getHits().getAt(0).getInnerHits().get("comment");
assertThat(innerHits.getTotalHits().value, equalTo(1L));
assertThat(innerHits.getAt(0).getId(), equalTo("3"));
assertThat(innerHits.getAt(0).getType(), equalTo("doc"));

innerHits = innerHits.getAt(0).getInnerHits().get("remark");
assertThat(innerHits.getTotalHits().value, equalTo(1L));
assertThat(innerHits.getAt(0).getId(), equalTo("5"));
assertThat(innerHits.getAt(0).getType(), equalTo("doc"));

response = client().prepareSearch("articles")
.setQuery(
Expand All @@ -455,12 +441,10 @@ public void testParentChildMultipleLayers() throws Exception {
innerHits = response.getHits().getAt(0).getInnerHits().get("comment");
assertThat(innerHits.getTotalHits().value, equalTo(1L));
assertThat(innerHits.getAt(0).getId(), equalTo("4"));
assertThat(innerHits.getAt(0).getType(), equalTo("doc"));

innerHits = innerHits.getAt(0).getInnerHits().get("remark");
assertThat(innerHits.getTotalHits().value, equalTo(1L));
assertThat(innerHits.getAt(0).getId(), equalTo("6"));
assertThat(innerHits.getAt(0).getType(), equalTo("doc"));
}

public void testRoyals() throws Exception {
Expand Down Expand Up @@ -613,7 +597,7 @@ public void testUseMaxDocInsteadOfSize() throws Exception {
assertHitCount(response, 1);
}

public void testNestedInnerHitWrappedInParentChildInnerhit() throws Exception {
public void testNestedInnerHitWrappedInParentChildInnerhit() {
assertAcked(
prepareCreate("test").addMapping(
"doc",
Expand Down Expand Up @@ -646,7 +630,7 @@ public void testNestedInnerHitWrappedInParentChildInnerhit() throws Exception {
assertThat(hit.getInnerHits().get("child_type").getAt(0).getInnerHits().get("nested_type").getAt(0).field("_parent"), nullValue());
}

public void testInnerHitsWithIgnoreUnmapped() throws Exception {
public void testInnerHitsWithIgnoreUnmapped() {
assertAcked(
prepareCreate("index1").addMapping(
"doc",
Expand Down Expand Up @@ -676,7 +660,7 @@ public void testInnerHitsWithIgnoreUnmapped() throws Exception {
assertSearchHits(response, "1", "3");
}

public void testTooHighResultWindow() throws Exception {
public void testTooHighResultWindow() {
assertAcked(
prepareCreate("index1").addMapping(
"doc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,29 @@ teardown:

- match: { hits.total: 6 }
- match: { hits.hits.0._index: "test" }
- match: { hits.hits.0._type: "_doc" }
- match: { hits.hits.0._id: "3" }
- match: { hits.hits.0._source.join_field.name: "child" }
- match: { hits.hits.0._source.join_field.parent: "1" }
- is_false: hits.hits.0.fields.join_field#child }
- match: { hits.hits.1._index: "test" }
- match: { hits.hits.1._type: "_doc" }
- match: { hits.hits.1._id: "4" }
- match: { hits.hits.1._source.join_field.name: "child" }
- match: { hits.hits.1._source.join_field.parent: "1" }
- is_false: hits.hits.1.fields.join_field#child }
- match: { hits.hits.2._index: "test" }
- match: { hits.hits.2._type: "_doc" }
- match: { hits.hits.2._id: "5" }
- match: { hits.hits.2._source.join_field.name: "child" }
- match: { hits.hits.2._source.join_field.parent: "2" }
- is_false: hits.hits.2.fields.join_field#child }
- match: { hits.hits.3._index: "test" }
- match: { hits.hits.3._type: "_doc" }
- match: { hits.hits.3._id: "6" }
- match: { hits.hits.3._source.join_field.name: "grand_child" }
- match: { hits.hits.3._source.join_field.parent: "5" }
- match: { hits.hits.4._index: "test" }
- match: { hits.hits.4._type: "_doc" }
- match: { hits.hits.4._id: "1" }
- match: { hits.hits.4._source.join_field.name: "parent" }
- is_false: hits.hits.4._source.join_field.parent
- match: { hits.hits.5._index: "test" }
- match: { hits.hits.5._type: "_doc" }
- match: { hits.hits.5._id: "2" }
- match: { hits.hits.5._source.join_field.name: "parent" }
- is_false: hits.hits.5._source.join_field.parent
Expand All @@ -96,12 +90,10 @@ teardown:

- match: { hits.total: 2 }
- match: { hits.hits.0._index: "test" }
- match: { hits.hits.0._type: "_doc" }
- match: { hits.hits.0._id: "3" }
- match: { hits.hits.0._source.join_field.name: "child" }
- match: { hits.hits.0._source.join_field.parent: "1" }
- match: { hits.hits.1._index: "test" }
- match: { hits.hits.1._type: "_doc" }
- match: { hits.hits.1._id: "4" }
- match: { hits.hits.1._source.join_field.name: "child" }
- match: { hits.hits.1._source.join_field.parent: "1" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,6 @@ public void testWithMultiplePercolatorFields() throws Exception {
.get();
assertHitCount(response, 1);
assertThat(response.getHits().getAt(0).getId(), equalTo("1"));
assertThat(response.getHits().getAt(0).getType(), equalTo("type"));
assertThat(response.getHits().getAt(0).getIndex(), equalTo("test1"));

response = client().prepareSearch()
Expand All @@ -898,7 +897,6 @@ public void testWithMultiplePercolatorFields() throws Exception {
.get();
assertHitCount(response, 1);
assertThat(response.getHits().getAt(0).getId(), equalTo("1"));
assertThat(response.getHits().getAt(0).getType(), equalTo("type"));
assertThat(response.getHits().getAt(0).getIndex(), equalTo("test2"));

// Unacceptable:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.lucene.search.QueryVisitor;
import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.document.DocumentField;
import org.opensearch.common.text.Text;
import org.opensearch.search.SearchHit;
import org.opensearch.search.fetch.FetchContext;
import org.opensearch.search.fetch.FetchSubPhase;
Expand Down Expand Up @@ -108,13 +107,7 @@ public void process(HitContext hit) throws IOException {
int slot = (int) matchedSlot;
BytesReference document = percolateQuery.getDocuments().get(slot);
HitContext subContext = new HitContext(
new SearchHit(
slot,
"unknown",
new Text(hit.hit().getType()),
Collections.emptyMap(),
Collections.emptyMap()
),
new SearchHit(slot, "unknown", Collections.emptyMap(), Collections.emptyMap()),
percolatorLeafReaderContext,
slot,
new SourceLookup()
Expand Down
Loading

0 comments on commit 3445bef

Please sign in to comment.