# Unexpected behavior when using match\_bool\_prefix with synonyms

**URL:** <https://discuss.elastic.co/t/unexpected-behavior-when-using-match-bool-prefix-with-synonyms/383755>\
**Category:** Elasticsearch\
**Created:** [November 28, 2025, 11:21am UTC](https://discuss.elastic.co/t/unexpected-behavior-when-using-match-bool-prefix-with-synonyms/383755 "2025-11-28T11:21:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gs\_elastic](https://avatars.discourse-cdn.com/v4/letter/g/b19c9b/32.png) [@gs\_elastic](https://discuss.elastic.co/u/gs_elastic)\
**Post date:** [November 28, 2025, 11:21am UTC](https://discuss.elastic.co/t/unexpected-behavior-when-using-match-bool-prefix-with-synonyms/383755/1 "2025-11-28T11:21:07Z")

</div>

I'm experiencing unexpected behavior when using `match_bool_prefix` together with a `synonym_graph` filter on the **search analyzer**.  
I found a similar topic previously asked:  
[Prefix query not matching any documents](https://discuss.elastic.co/t/prefix-query-not-matching-any-documents/368943) — I used the example from that thread, and I encounter the same problem here.

```auto
PUT henkel-test
{
  "settings": {
    "analysis": {
      "filter": {
        "synonyms_filter": {
          "type": "synonym_graph",
            "synonyms": [
            "henke, henk"
          ],
          "updateable": true
        }
      },
      "analyzer": {
        "my_index_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": ["lowercase"]
        },
        "my_search_analyzer": {
          "type": "custom",
          "tokenizer": "standard",
          "filter": ["lowercase", "synonyms_filter"]
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "text": {
        "type": "text",
        "analyzer": "my_index_analyzer",
        "search_analyzer": "my_search_analyzer"
      }
    }
  }
}

PUT henkel-test/_doc/1
{
  "text": "CT17 TRANSPARENT GRUNT 2L HENKEL"
}

POST henkel-test/_search
{
  "profile": true,
  "query": {
    "match_bool_prefix" : {
      "text" : "henk"
    }
  }
}

```

Searching for `"hen"` correctly matches `"henkel"`.

Searching for `"henk"` **does not match**.

I tested this on:  
Elasticsearch **8.15.2**  
Elasticsearch **9.2.1** — same result on both versions.

Is this expected behavior, or am i missing something? Since `match_bool_prefix` uses the **last term for partial (prefix) matching**, I expected: `"henk"` → would behave like a prefix and match `"henkel"`

---

<div class="post-metadata">

**Author:** ![Tortoise](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tortoise/32/147587_2.png) [@Tortoise](https://discuss.elastic.co/u/Tortoise)\
**Post date:** [November 30, 2025, 10:39am UTC](https://discuss.elastic.co/t/unexpected-behavior-when-using-match-bool-prefix-with-synonyms/383755/2 "2025-11-30T10:39:00Z")

</div>

Hello @gs_elastic

Welcome to the community!!

I also observed the same output as described in the post for 9.2.1 version.

On reviewing online using LLM i found below information related to this topic if it can be helpful which suggest this is not a bug but output is as expected :

Document indexed: token is henkel (index analyzer just lowercases).

1. Search "hen":  
Analyzer yields token hen.  
match\_bool\_prefix makes a prefix/multi-term query like hen\* → matches henkel.

2. Search "henk":  
Search analyzer runs synonyms: henk → henke (because your synonyms list contains henke, henk).  
The query becomes a SynonymQuery with exact terms (henk and henke) — no prefix expansion on the synonym term — so it does not match the indexed henkel.

match\_bool\_prefix constructs prefix queries for the final token after analysis. When synonyms replace that token with other tokens that are not prefixes of the indexed token you want, you lose the prefix match. Either make sure the synonym expansion includes the indexed form (henkel) or apply synonyms at index time so the indexed tokens include the variant you search for.

Because "henke, henk" is bidirectional, when you search "henk":  
Analyzer produces: henk  
Synonyms produce: henk, henke  
BUT no prefix query is applied after synonym expansion, so these become exact term queries, not henk\*.  
Your indexed token is henkel, which is not equal to henk or henke, so nothing matches.

Synonym Expansion: When using synonym\_graph, the expanded synonyms are treated as separate tokens. These tokens are matched using term queries, not prefix queries.  
Prefix Matching: The match\_bool\_prefix query applies prefix matching only to the last token produced by the analyzer. If the token graph contains multiple tokens at the same position, prefix matching may not work as intended.

Thanks!!

---

<div class="post-metadata">

**Author:** ![gs\_elastic](https://avatars.discourse-cdn.com/v4/letter/g/b19c9b/32.png) [@gs\_elastic](https://discuss.elastic.co/u/gs_elastic)\
**Post date:** [December 1, 2025, 7:15am UTC](https://discuss.elastic.co/t/unexpected-behavior-when-using-match-bool-prefix-with-synonyms/383755/3 "2025-12-01T07:15:25Z")

</div>

Thank you for the detailed explanation — The part about how synonym\_graph produces multiple tokens at the same position, preventing match\_bool\_prefix from applying prefix logic, makes sense.

It might still be useful if the official documentation mentioned this interaction explicitly, as it can be confusing when first encountered. I also noticed that the match query docs include a note about how synonyms interact with fuzziness, and a similar note here could help avoid confusion:  
[https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-match-query#query-dsl-match-query-fuzziness](https://www.elastic.co/docs/reference/query-languages/query-dsl/query-dsl-match-query#query-dsl-match-query-fuzziness)
