Skip to content

Commit

Permalink
Avoid duplicate _type fields in v7 compat layer (elastic#83239)
Browse files Browse the repository at this point in the history
Relates elastic#83195 (comment)
  • Loading branch information
ywelsch authored Jan 29, 2022
1 parent 878a445 commit 87ee045
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ public XContentBuilder toInnerXContent(XContentBuilder builder, Params params) t
if (index != null) {
builder.field(Fields._INDEX, RemoteClusterAware.buildRemoteIndexName(clusterAlias, index));
}
if (builder.getRestApiVersion() == RestApiVersion.V_7) {
if (builder.getRestApiVersion() == RestApiVersion.V_7 && metaFields.containsKey(MapperService.TYPE_FIELD_NAME) == false) {
builder.field(MapperService.TYPE_FIELD_NAME, MapperService.SINGLE_MAPPING_NAME);
}
if (id != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,14 @@ private void assertDocs(
boolean sourceOnlyRepository,
Version oldVersion
) throws IOException {
RequestOptions v7RequestOptions = RequestOptions.DEFAULT.toBuilder()
.addHeader("Content-Type", "application/vnd.elasticsearch+json;compatible-with=7")
.addHeader("Accept", "application/vnd.elasticsearch+json;compatible-with=7")
.build();
RequestOptions randomRequestOptions = randomBoolean() ? RequestOptions.DEFAULT : v7RequestOptions;

// run a search against the index
SearchResponse searchResponse = client.search(new SearchRequest(index), RequestOptions.DEFAULT);
SearchResponse searchResponse = client.search(new SearchRequest(index), randomRequestOptions);
logger.info(searchResponse);
// check hit count
assertEquals(numDocs, searchResponse.getHits().getTotalHits().value);
Expand All @@ -420,7 +426,7 @@ private void assertDocs(
.query(QueryBuilders.matchQuery("val", num))
.runtimeMappings(Map.of("val", Map.of("type", "long")))
),
RequestOptions.DEFAULT
randomRequestOptions
);
logger.info(searchResponse);
assertEquals(1, searchResponse.getHits().getTotalHits().value);
Expand All @@ -445,7 +451,7 @@ private void assertDocs(
.query(QueryBuilders.matchAllQuery())
.sort(SortBuilders.fieldSort("val").order(SortOrder.DESC))
),
RequestOptions.DEFAULT
randomRequestOptions
);
logger.info(searchResponse);
// check sort order
Expand All @@ -460,7 +466,7 @@ private void assertDocs(
long typeCount = expectedIds.stream().filter(idd -> getType(oldVersion, idd).equals(randomType)).count();
searchResponse = client.search(
new SearchRequest(index).source(SearchSourceBuilder.searchSource().query(QueryBuilders.termQuery("_type", randomType))),
RequestOptions.DEFAULT
randomRequestOptions
);
logger.info(searchResponse);
assertEquals(typeCount, searchResponse.getHits().getTotalHits().value);
Expand Down

0 comments on commit 87ee045

Please sign in to comment.