Skip to content

[BUG] Sorted Order Assertion in LongHashSet.java is incorrect #17206

@Shailesh-Kumar-Singh

Description

@Shailesh-Kumar-Singh

Describe the bug

The assertion logic in LongHashSet.java assumes signed long values, which leads to incorrect validation when dealing with unsigned long values. The sorted order check fails because value >= previousValue does not correctly handle unsigned comparisons.

Related component

Search

To Reproduce

  1. Run ./gradlew run
  2. Create the Index
    PUT test_index
{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 0
    }
  },
  "mappings": {
    "properties": {
      "stat": {
        "type": "unsigned_long"
      },
      "latency": {
        "type": "long"
      }
    }
  }
}
  1. Ingest sample documents
  2. Run Query -
    POST test_index/_search
{
  "query": {
    "terms": {
      "stat": [
        "9223372036854775814",
        "9223372036854775812",
        "9223372036854775811",
        "1"
      ]
    }
  },
  "aggs": {
    "sum_size": {
      "sum": {
        "field": "latency"
      }
    }
  }
}
  1. We get - [Please check Additional Details below for Stack trace]
»  fatal error in thread [opensearch[runTask-0][search][T#1]], exiting
»  java.lang.AssertionError: values must be provided in sorted order
FAILURE: Build failed with an exception. 

Expected behavior

In the normal flow, the query should correctly apply Terms aggregations without assertion errors.

Additional Details

Stack Trace

»  java.lang.AssertionError: values must be provided in sorted order
»       at org.apache.lucene.util.LongHashSet.assertBasedOnDataType(LongHashSet.java:68)
»       at org.apache.lucene.util.LongHashSet.<init>(LongHashSet.java:55)
»       at org.opensearch.index.document.SortedUnsignedLongDocValuesSetQuery.<init>(SortedUnsignedLongDocValuesSetQuery.java:48)
»       at org.opensearch.index.document.SortedUnsignedLongDocValuesSetQuery$2.<init>(SortedUnsignedLongDocValuesSetQuery.java:150)
»       at org.opensearch.index.document.SortedUnsignedLongDocValuesSetQuery.newSlowSetQuery(SortedUnsignedLongDocValuesSetQuery.java:150)
»       at org.opensearch.index.mapper.NumberFieldMapper$NumberType$8.termsQuery(NumberFieldMapper.java:1168)
»       at org.opensearch.index.mapper.NumberFieldMapper$NumberFieldType.termsQuery(NumberFieldMapper.java:1577)
»       at org.opensearch.index.query.TermsQueryBuilder.doToQuery(TermsQueryBuilder.java:556)
»       at org.opensearch.index.query.AbstractQueryBuilder.toQuery(AbstractQueryBuilder.java:117)
»       at org.opensearch.index.query.QueryShardContext.lambda$toQuery$3(QueryShardContext.java:575)
»       at org.opensearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:587)
»       at org.opensearch.index.query.QueryShardContext.toQuery(QueryShardContext.java:574)
»       at org.opensearch.search.SearchService.parseSource(SearchService.java:1374)
»       at org.opensearch.search.SearchService.createContext(SearchService.java:1110)
»       at org.opensearch.search.SearchService.executeQueryPhase(SearchService.java:707)
»       at org.opensearch.search.SearchService$2.lambda$onResponse$0(SearchService.java:680)
»       at org.opensearch.action.ActionRunnable.lambda$supply$0(ActionRunnable.java:74)
»       at org.opensearch.action.ActionRunnable$2.doRun(ActionRunnable.java:89)
»       at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52)
»       at org.opensearch.threadpool.TaskAwareRunnable.doRun(TaskAwareRunnable.java:78)
»       at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52)
»       at org.opensearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:59)
»       at org.opensearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:994)
»       at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52)
»       at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
»       at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
»       at java.base/java.lang.Thread.run(Thread.java:1583)

Metadata

Metadata

Assignees

No one assigned

    Labels

    SearchSearch query, autocomplete ...etcbugSomething isn't working

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions