Skip to content

Commit

Permalink
Fix issue with float field terms query
Browse files Browse the repository at this point in the history
Signed-off-by: Harsha Vamsi Kalluri <[email protected]>
  • Loading branch information
harshavamsi committed Feb 29, 2024
1 parent fb41756 commit 2ea445d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.index.IndexSettings;
import org.opensearch.index.mapper.MapperService;
import org.opensearch.index.query.ConstantScoreQueryBuilder;
import org.opensearch.index.query.QueryBuilders;
import org.opensearch.index.query.TermQueryBuilder;
import org.opensearch.search.rescore.QueryRescorerBuilder;
import org.opensearch.search.sort.SortOrder;
import org.opensearch.test.ParameterizedStaticSettingsOpenSearchIntegTestCase;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -676,6 +678,23 @@ public void testTermQueryBigInt() throws Exception {
assertEquals(1, searchResponse.getHits().getTotalHits().value);
}

public void testIndexOnlyFloatField() throws IOException {
prepareCreate("idx").setMapping("field", "type=float,doc_values=false").get();
ensureGreen("idx");

IndexRequestBuilder indexRequestBuilder = client().prepareIndex("idx");

for (float i = 9000.0F; i < 20000.0F; i++) {
indexRequestBuilder.setId(String.valueOf(i)).setSource("{\"field\":" + i + "}", MediaTypeRegistry.JSON).get();
}
String queryJson = "{ \"filter\" : { \"terms\" : { \"field\" : [ 10000.0 ] } } }";
XContentParser parser = createParser(JsonXContent.jsonXContent, queryJson);
parser.nextToken();
ConstantScoreQueryBuilder query = ConstantScoreQueryBuilder.fromXContent(parser);
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(query).get();
assertEquals(1, searchResponse.getHits().getTotalHits().value);
}

public void testTooLongRegexInRegexpQuery() throws Exception {
createIndex("idx");
indexRandom(true, client().prepareIndex("idx").setSource("{}", MediaTypeRegistry.JSON));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

import org.apache.lucene.document.DoublePoint;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FloatField;
import org.apache.lucene.document.FloatPoint;
import org.apache.lucene.document.IntPoint;
import org.apache.lucene.document.LongPoint;
Expand Down Expand Up @@ -372,7 +371,7 @@ public Query termsQuery(String field, List<Object> values, boolean hasDocValues,
if (hasDocValues) {
return SortedNumericDocValuesField.newSlowSetQuery(field, points);
}
return FloatField.newSetQuery(field, v);
return FloatPoint.newSetQuery(field, v);
}

@Override
Expand Down

0 comments on commit 2ea445d

Please sign in to comment.