Skip to content

Commit 8a22f28

Browse files
authored
Fix issue with float field terms query (#12499)
Signed-off-by: Harsha Vamsi Kalluri <harshavamsi096@gmail.com>
1 parent 5a086c5 commit 8a22f28

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
137137
- Prevent read beyond slice boundary in ByteArrayIndexInput ([#10481](https://github.com/opensearch-project/OpenSearch/issues/10481))
138138
- Fix the "highlight.max_analyzer_offset" request parameter with "plain" highlighter ([#10919](https://github.com/opensearch-project/OpenSearch/pull/10919))
139139
- Warn about deprecated and ignored index.mapper.dynamic index setting ([#11193](https://github.com/opensearch-project/OpenSearch/pull/11193))
140+
- Fix `terms` query on `float` field when `doc_values` are turned off by reverting back to `FloatPoint` from `FloatField` ([#12499](https://github.com/opensearch-project/OpenSearch/pull/12499))
140141
- Fix get task API does not refresh resource stats ([#11531](https://github.com/opensearch-project/OpenSearch/pull/11531))
141142

142143
### Security

server/src/internalClusterTest/java/org/opensearch/search/simple/SimpleSearchIT.java

+19
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@
4747
import org.opensearch.core.xcontent.XContentParser;
4848
import org.opensearch.index.IndexSettings;
4949
import org.opensearch.index.mapper.MapperService;
50+
import org.opensearch.index.query.ConstantScoreQueryBuilder;
5051
import org.opensearch.index.query.QueryBuilders;
5152
import org.opensearch.index.query.TermQueryBuilder;
5253
import org.opensearch.search.rescore.QueryRescorerBuilder;
5354
import org.opensearch.search.sort.SortOrder;
5455
import org.opensearch.test.ParameterizedStaticSettingsOpenSearchIntegTestCase;
5556

57+
import java.io.IOException;
5658
import java.util.ArrayList;
5759
import java.util.Arrays;
5860
import java.util.Collection;
@@ -676,6 +678,23 @@ public void testTermQueryBigInt() throws Exception {
676678
assertEquals(1, searchResponse.getHits().getTotalHits().value);
677679
}
678680

681+
public void testIndexOnlyFloatField() throws IOException {
682+
prepareCreate("idx").setMapping("field", "type=float,doc_values=false").get();
683+
ensureGreen("idx");
684+
685+
IndexRequestBuilder indexRequestBuilder = client().prepareIndex("idx");
686+
687+
for (float i = 9000.0F; i < 20000.0F; i++) {
688+
indexRequestBuilder.setId(String.valueOf(i)).setSource("{\"field\":" + i + "}", MediaTypeRegistry.JSON).get();
689+
}
690+
String queryJson = "{ \"filter\" : { \"terms\" : { \"field\" : [ 10000.0 ] } } }";
691+
XContentParser parser = createParser(JsonXContent.jsonXContent, queryJson);
692+
parser.nextToken();
693+
ConstantScoreQueryBuilder query = ConstantScoreQueryBuilder.fromXContent(parser);
694+
SearchResponse searchResponse = client().prepareSearch("idx").setQuery(query).get();
695+
assertEquals(1, searchResponse.getHits().getTotalHits().value);
696+
}
697+
679698
public void testTooLongRegexInRegexpQuery() throws Exception {
680699
createIndex("idx");
681700
indexRandom(true, client().prepareIndex("idx").setSource("{}", MediaTypeRegistry.JSON));

server/src/main/java/org/opensearch/index/mapper/NumberFieldMapper.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737

3838
import org.apache.lucene.document.DoublePoint;
3939
import org.apache.lucene.document.Field;
40-
import org.apache.lucene.document.FloatField;
4140
import org.apache.lucene.document.FloatPoint;
4241
import org.apache.lucene.document.IntPoint;
4342
import org.apache.lucene.document.LongPoint;
@@ -372,7 +371,7 @@ public Query termsQuery(String field, List<Object> values, boolean hasDocValues,
372371
if (hasDocValues) {
373372
return SortedNumericDocValuesField.newSlowSetQuery(field, points);
374373
}
375-
return FloatField.newSetQuery(field, v);
374+
return FloatPoint.newSetQuery(field, v);
376375
}
377376

378377
@Override

0 commit comments

Comments
 (0)