Skip to content

[BUG] Collapsing search results with concurrent segment search enabled triggers assertion errorΒ #19051

@gaobinlong

Description

@gaobinlong

Describe the bug

When collapsing search results with concurrent segment search enabled, an assertion error shardIndex is already set is triggered here:

assert topDocs.scoreDocs.length == 0 || topDocs.scoreDocs[0].shardIndex == -1 : "shardIndex is already set";

, seems that we set the shardIndex twice.

Related component

Search

To Reproduce

  1. Run OpenSearch in debugging mode
  2. Enable concurrent segment search and execute search with field collapsing and
PUT abcd_test/_settings
{
    "index.search.concurrent_segment_search.mode": "all"
}

GET abcd_test/_search?size=1
{
  "query": {
    "match": {
      "b": "1"
    }
  },
  "collapse": {
    "field": "a"
  }
}

Then you can see that an assertion error crashes the node

[2025-08-13T16:23:50,319][ERROR][o.o.b.OpenSearchUncaughtExceptionHandler] [node-1] fatal error in thread [opensearch[node-1][search][T#2]], exiting
java.lang.AssertionError: shardIndex is already set
	at org.opensearch.action.search.SearchPhaseController.setShardIndex(SearchPhaseController.java:248) ~[classes/:?]
	at org.opensearch.action.search.QueryPhaseResultConsumer$PendingMerges.consumeTopDocs(QueryPhaseResultConsumer.java:489) ~[classes/:?]
	at org.opensearch.action.search.QueryPhaseResultConsumer.reduce(QueryPhaseResultConsumer.java:150) ~[classes/:?]
	at org.opensearch.action.search.FetchSearchPhase.innerRun(FetchSearchPhase.java:136) ~[classes/:?]
	at org.opensearch.action.search.FetchSearchPhase$1.doRun(FetchSearchPhase.java:122) ~[classes/:?]
	at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52) ~[classes/:?]
	at org.opensearch.threadpool.TaskAwareRunnable.doRun(TaskAwareRunnable.java:78) ~[classes/:?]
	at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52) ~[classes/:?]
	at org.opensearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:59) ~[classes/:?]
	at org.opensearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:975) ~[classes/:?]
	at org.opensearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:52) ~[classes/:?]
	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:1575) [?:?]

Expected behavior

shardIndex of the topDocs should be set only once.

Additional Details

Host/Environment (please complete the following information):

  • Version [3.2 and main branch]

Metadata

Metadata

Assignees

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