Description
I’m using the ReactiveElasticsearchClient in my Spring Boot application, and I’m trying to perform a single search request that includes both a query and suggestions across multiple indices.
Each index has slightly different mappings — for example, some fields exist in one index but not the other.
The search part works fine, but the suggest section causes an error whenever a field doesn’t exist in one of the indices.
I want to run a combined search + suggest request across indices with partially overlapping mappings.
However, Elasticsearch fails with an error about missing field mappings.
Example setup
Index 1: theme_index
PUT theme_index
{
"mappings": {
"properties": {
"theme_name": {
"type": "text",
"fields": {
"suggest": {
"type": "completion"
}
}
},
"description": { "type": "text" }
}
}
}
Index 2: color_index
PUT color_index
{
"mappings": {
"properties": {
"color_name": {
"type": "text",
"fields": {
"suggest": {
"type": "completion"
}
}
},
"hex_value": { "type": "keyword" }
}
}
}
Insert sample data :
POST theme_index/_doc { "theme_name": "Nature", "description": "Green and calm tones" }
POST color_index/_doc { "color_name": "Emerald", "hex_value": "#50C878" }
Combined search + suggest query :
POST theme_index,color_index/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"theme_name": "green"
}
},
{
"match": {
"color_name": "green"
}
}
],
"minimum_should_match": 1
}
},
"suggest": {
"theme-suggest": {
"prefix": "gr",
"completion": {
"field": "theme_name.suggest",
"fuzzy": true
}
},
"color-suggest": {
"prefix": "gr",
"completion": {
"field": "color_name.suggest",
"fuzzy": true
}
}
}
}
Error message :
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "No mapping found for field [theme_name.suggest] in index [color_index]"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed"
},
"status": 400
}
Expected behavior
I expected Elasticsearch to:
-
Run the query on all indices
-
Run the suggest part only on indices where the specified field exists, or skip if it’s missing
What I’ve tried
I found that using Multi Search (_msearch
) works as a workaround — by sending individual suggest queries for each index.
However, the ReactiveElasticsearchClient does not provide a multiSearch()
API, so I can’t easily use it in a reactive way.
Question :
Is there any other way to:
-
Run a single search + suggest request safely when field mappings differ across indices,
or -
Implement a reactive multi-search workaround using
ReactiveElasticsearchClient
?