Skip to content

Commit

Permalink
Replace DocValuesFieldExistsQuery with FieldExistsQuery
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Ross <[email protected]>
  • Loading branch information
andrross committed Nov 13, 2024
1 parent 1ab1a5f commit 0fafd24
Show file tree
Hide file tree
Showing 20 changed files with 143 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.apache.lucene.document.Document;
import org.apache.lucene.document.LatLonPoint;
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.search.DocValuesFieldExistsQuery;
import org.apache.lucene.search.FieldExistsQuery;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.opensearch.common.geo.GeoPoint;
import org.opensearch.geo.GeoModulePlugin;
Expand Down Expand Up @@ -60,15 +60,15 @@ public void testUnmappedFieldWithGeopoint() throws Exception {

// just unmapped = no results
testSearchCase(
Arrays.asList(new MatchAllDocsQuery(), new DocValuesFieldExistsQuery(mappedFieldName)),
Arrays.asList(new MatchAllDocsQuery(), new FieldExistsQuery(mappedFieldName)),
dataset,
() -> new CompositeAggregationBuilder("name", Arrays.asList(new GeoTileGridValuesSourceBuilder("unmapped").field("unmapped"))),
(result) -> assertEquals(0, result.getBuckets().size())
);

// unmapped missing bucket = one result
testSearchCase(
Arrays.asList(new MatchAllDocsQuery(), new DocValuesFieldExistsQuery(mappedFieldName)),
Arrays.asList(new MatchAllDocsQuery(), new FieldExistsQuery(mappedFieldName)),
dataset,
() -> new CompositeAggregationBuilder(
"name",
Expand All @@ -84,7 +84,7 @@ public void testUnmappedFieldWithGeopoint() throws Exception {

// field + unmapped, no missing bucket = no results
testSearchCase(
Arrays.asList(new MatchAllDocsQuery(), new DocValuesFieldExistsQuery(mappedFieldName)),
Arrays.asList(new MatchAllDocsQuery(), new FieldExistsQuery(mappedFieldName)),
dataset,
() -> new CompositeAggregationBuilder(
"name",
Expand All @@ -98,7 +98,7 @@ public void testUnmappedFieldWithGeopoint() throws Exception {

// field + unmapped with missing bucket = multiple results
testSearchCase(
Arrays.asList(new MatchAllDocsQuery(), new DocValuesFieldExistsQuery(mappedFieldName)),
Arrays.asList(new MatchAllDocsQuery(), new FieldExistsQuery(mappedFieldName)),
dataset,
() -> new CompositeAggregationBuilder(
"name",
Expand Down Expand Up @@ -130,7 +130,7 @@ public void testWithGeoPoint() throws Exception {
createDocument("geo_point", new GeoPoint(90.0, 0.0))
)
);
testSearchCase(Arrays.asList(new MatchAllDocsQuery(), new DocValuesFieldExistsQuery("geo_point")), dataset, () -> {
testSearchCase(Arrays.asList(new MatchAllDocsQuery(), new FieldExistsQuery("geo_point")), dataset, () -> {
GeoTileGridValuesSourceBuilder geoTile = new GeoTileGridValuesSourceBuilder("geo_point").field("geo_point");
return new CompositeAggregationBuilder("name", Collections.singletonList(geoTile));
}, (result) -> {
Expand All @@ -142,7 +142,7 @@ public void testWithGeoPoint() throws Exception {
assertEquals(3L, result.getBuckets().get(1).getDocCount());
});

testSearchCase(Arrays.asList(new MatchAllDocsQuery(), new DocValuesFieldExistsQuery("geo_point")), dataset, () -> {
testSearchCase(Arrays.asList(new MatchAllDocsQuery(), new FieldExistsQuery("geo_point")), dataset, () -> {
GeoTileGridValuesSourceBuilder geoTile = new GeoTileGridValuesSourceBuilder("geo_point").field("geo_point");
return new CompositeAggregationBuilder("name", Collections.singletonList(geoTile)).aggregateAfter(
Collections.singletonMap("geo_point", "7/32/56")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.DocValuesFieldExistsQuery;
import org.apache.lucene.search.FieldExistsQuery;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.TermQuery;
import org.opensearch.Version;
Expand All @@ -50,7 +50,7 @@ public void testNonNestedQuery() {
// This is a custom query that extends AutomatonQuery and want to make sure the equals method works
assertEquals(Queries.newNonNestedFilter(), Queries.newNonNestedFilter());
assertEquals(Queries.newNonNestedFilter().hashCode(), Queries.newNonNestedFilter().hashCode());
assertEquals(Queries.newNonNestedFilter(), new DocValuesFieldExistsQuery(SeqNoFieldMapper.PRIMARY_TERM_NAME));
assertEquals(Queries.newNonNestedFilter(), new FieldExistsQuery(SeqNoFieldMapper.PRIMARY_TERM_NAME));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.apache.lucene.document.SortedNumericDocValuesField;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.DocValuesFieldExistsQuery;
import org.apache.lucene.search.FieldExistsQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.util.BytesRef;
Expand Down Expand Up @@ -85,7 +85,7 @@ public void testTermsQuery() {
List<BytesRef> terms = new ArrayList<>();
terms.add(new BytesRef("true"));
terms.add(new BytesRef("false"));
assertEquals(new DocValuesFieldExistsQuery("field"), ft.termsQuery(terms, null));
assertEquals(new FieldExistsQuery("field"), ft.termsQuery(terms, null));

List<BytesRef> newTerms = new ArrayList<>();
newTerms.add(new BytesRef("true"));
Expand All @@ -108,7 +108,7 @@ public void testTermsQuery() {

public void testRangeQuery() {
BooleanFieldMapper.BooleanFieldType ft = new BooleanFieldMapper.BooleanFieldType("field");
assertEquals(new DocValuesFieldExistsQuery("field"), ft.rangeQuery(false, true, true, true, null));
assertEquals(new FieldExistsQuery("field"), ft.rangeQuery(false, true, true, true, null));

assertEquals(new TermQuery(new Term("field", "T")), ft.rangeQuery(false, true, false, true, null));

Expand All @@ -122,7 +122,7 @@ public void testRangeQuery() {

assertEquals(new TermQuery(new Term("field", "F")), ft.rangeQuery(null, false, true, true, null));

assertEquals(new DocValuesFieldExistsQuery("field"), ft.rangeQuery(false, null, true, true, null));
assertEquals(new FieldExistsQuery("field"), ft.rangeQuery(false, null, true, true, null));

IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> ft.rangeQuery("random", null, true, true, null));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
package org.opensearch.index.mapper;

import org.apache.lucene.search.DocValuesFieldExistsQuery;
import org.apache.lucene.search.FieldExistsQuery;
import org.opensearch.index.query.QueryShardException;

import java.io.IOException;
Expand All @@ -56,7 +56,7 @@ public void testRangeQuery() {

public void testExistsQuery() {
MappedFieldType ft = new DocCountFieldMapper.DocCountFieldType();
assertTrue(ft.existsQuery(randomMockShardContext()) instanceof DocValuesFieldExistsQuery);
assertTrue(ft.existsQuery(randomMockShardContext()) instanceof FieldExistsQuery);
}

public void testFetchSourceValue() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.DocValuesFieldExistsQuery;
import org.apache.lucene.search.FieldExistsQuery;
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.IndexOrDocValuesQuery;
import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.NormsFieldExistsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.RegexpQuery;
import org.apache.lucene.search.TermInSetQuery;
Expand Down Expand Up @@ -160,13 +159,13 @@ public void testTermsQuery() {
public void testExistsQuery() {
{
KeywordFieldType ft = new KeywordFieldType("field");
assertEquals(new DocValuesFieldExistsQuery("field"), ft.existsQuery(null));
assertEquals(new FieldExistsQuery("field"), ft.existsQuery(null));
}
{
FieldType fieldType = new FieldType();
fieldType.setOmitNorms(false);
KeywordFieldType ft = new KeywordFieldType("field", fieldType);
assertEquals(new NormsFieldExistsQuery("field"), ft.existsQuery(null));
assertEquals(new FieldExistsQuery("field"), ft.existsQuery(null));
}
{
KeywordFieldType ft = new KeywordFieldType("field", true, false, Collections.emptyMap());
Expand Down
Loading

0 comments on commit 0fafd24

Please sign in to comment.