forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix term stats when talking to ES 6 (elastic#75735)
In a mixed 6.x and 7.x cluster, a search that uses dfs_query_then_fetch can cause a transport serialization errors. This is related to https://issues.apache.org/jira/browse/LUCENE-8007, which was introduced in Lucene 8 and adds stricter checks to TermStatistics and CollectionStatistics, and https://issues.apache.org/jira/browse/LUCENE-8020, which was introduced in Lucene 8 and avoids bogus term stats (e.g. docfreq=0). Co-authored-by: Julie Tibshirani [email protected] Closes elastic#75349
- Loading branch information
Showing
6 changed files
with
176 additions
and
7 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
qa/rolling-upgrade/src/test/resources/rest-api-spec/test/mixed_cluster/30_dfs_query.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
"Perform a dfs_query_then_fetch search on a keyword field": | ||
- do: | ||
search: | ||
search_type: dfs_query_then_fetch | ||
index: keyword_index | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
match: | ||
field: | ||
query: value | ||
|
||
- match: { hits.total: 3 } |
43 changes: 43 additions & 0 deletions
43
qa/rolling-upgrade/src/test/resources/rest-api-spec/test/old_cluster/30_dfs_query.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
"Perform a dfs_query_then_fetch search on a keyword field": | ||
- do: | ||
indices.create: | ||
index: keyword_index | ||
body: | ||
mappings: | ||
properties: | ||
field: | ||
type: keyword | ||
- do: | ||
index: | ||
index: keyword_index | ||
body: | ||
field: value | ||
refresh: true | ||
|
||
- do: | ||
index: | ||
index: keyword_index | ||
body: | ||
field: value | ||
refresh: true | ||
|
||
- do: | ||
index: | ||
index: keyword_index | ||
body: | ||
field: value | ||
refresh: true | ||
|
||
- do: | ||
search: | ||
search_type: dfs_query_then_fetch | ||
index: keyword_index | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
match: | ||
field: | ||
query: value | ||
|
||
- match: { hits.total: 3 } |
14 changes: 14 additions & 0 deletions
14
qa/rolling-upgrade/src/test/resources/rest-api-spec/test/upgraded_cluster/30_dfs_query.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
"Perform a dfs_query_then_fetch search on a keyword field": | ||
- do: | ||
search: | ||
search_type: dfs_query_then_fetch | ||
index: keyword_index | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
match: | ||
field: | ||
query: value | ||
|
||
- match: { hits.total: 3 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
server/src/test/java/org/elasticsearch/search/dfs/DfsSearchResultTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.search.dfs; | ||
|
||
import com.carrotsearch.hppc.ObjectObjectHashMap; | ||
|
||
import org.apache.lucene.search.CollectionStatistics; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.common.bytes.BytesReference; | ||
import org.elasticsearch.common.io.stream.BytesStreamOutput; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.test.VersionUtils; | ||
|
||
import java.io.IOException; | ||
|
||
public class DfsSearchResultTests extends ESTestCase { | ||
|
||
/** | ||
* checks inputs from 6.x that are difficult to simulate in a BWC mixed-cluster test, in particular the case | ||
* where docCount == -1L which does not occur with the codecs that we typically use. | ||
*/ | ||
public void test6xSerialization() throws IOException { | ||
Version version = VersionUtils.randomVersionBetween(random(), Version.V_6_8_0, Version.V_6_8_18); | ||
BytesStreamOutput os = new BytesStreamOutput(); | ||
os.setVersion(version); | ||
os.writeVInt(1); | ||
String field = randomAlphaOfLength(10); | ||
os.writeString(field); | ||
long maxDoc = randomIntBetween(1, 5); | ||
os.writeVLong(maxDoc); | ||
long docCount = randomBoolean() ? -1 : randomIntBetween(1, (int) maxDoc); | ||
os.writeVLong(DfsSearchResult.addOne(docCount)); | ||
long sumTotalTermFreq = randomBoolean() ? -1 : randomIntBetween(20, 30); | ||
os.writeVLong(DfsSearchResult.addOne(sumTotalTermFreq)); | ||
long sumDocFreq = sumTotalTermFreq == -1 ? randomIntBetween(20, 30) : randomIntBetween(20, (int) sumTotalTermFreq); | ||
os.writeVLong(DfsSearchResult.addOne(sumDocFreq)); | ||
|
||
try (StreamInput input = StreamInput.wrap(BytesReference.toBytes(os.bytes()))) { | ||
input.setVersion(version); | ||
ObjectObjectHashMap<String, CollectionStatistics> stats = DfsSearchResult.readFieldStats(input); | ||
assertEquals(stats.size(), 1); | ||
assertNotNull(stats.get(field)); | ||
CollectionStatistics cs = stats.get(field); | ||
assertEquals(field, cs.field()); | ||
assertEquals(maxDoc, cs.maxDoc()); | ||
assertEquals(docCount == -1 ? maxDoc : docCount, cs.docCount()); | ||
assertEquals(sumDocFreq, cs.sumDocFreq()); | ||
assertEquals(sumTotalTermFreq == -1 ? sumDocFreq : sumTotalTermFreq, cs.sumTotalTermFreq()); | ||
} | ||
} | ||
} |