Prefix query not matching any documents

I have a document with name field containing "CT17 TRANSPARENT GRUNT 2L HENKEL" text. I'm trying to do match_bool_prefix query and I've got weird results.

If i search for "ct17 grunt hen" it gives me this document.
Same with "ct17 grunt henk" and "ct17 grunt henkel"
But "ct17 grunt henke" returns no results.

I ran these queries with profile: true option and it looks like for phrase "henke" it creates synonym query instead of prefix:
+name:ct17 +name:grunt +Synonym(name:henk name:henke)

Why is it doing that? How to prevent creating this SynonymQuery and leave prefix?

Do you have synonyms configured for this field? That seems to be what's going on here. Without synonyms, this should work with no issue:

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

POST henkel-test/_search
{
  "query": {
    "match_bool_prefix" : {
      "text" : "ct17 grunt henke"
    }
  }
}

Certainly there is synonym used, but I think behaviour of engine is wrong. When I use match_bool_prefix I expect last term is used for partial match. But in this case engine found synonym and replaces partial match with exact match of term "henke" and its synonyms.

Probably it would be better if this query resolves to something like +name:henke* OR +Synonym(name:henk name:henke)

What's interesting, when I use this query:

{
  "query": {
    "must": [
      {"term": {"name": "ct17"}},
      {"term": {"name": "grunt"}},
      {"prefix": {"name": "henke"}},
    ]
  }
}

which is described as equivalent to match_bool_prefix, everything works fine.

You're right that if the behavior is inconsistent that's probably a bug.

The issue that I'm running into, is that I can't duplicate this problem right now. Here's a sample script that I used on 8.15.2, but both the match_bool_prefix and bool queries perform exactly the same.

PUT _synonyms/my-synonyms-set
{
  "synonyms_set": [
    {
      "synonyms": "henke, henk"
    }
  ]
}

PUT henkel-test
{
  "settings": {
    "analysis": {
      "filter": {
        "synonyms_filter": {
          "type": "synonym_graph",
          "synonyms_set": "my-synonyms-set",
          "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
{
  "query": {
    "match_bool_prefix" : {
      "text" : "ct17 grunt henke"
    }
  }
}

POST henkel-test/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "text": "ct17"
          }
        },
        {
          "term": {
            "text": "grunt"
          }
        },
        {
          "prefix": {
            "text": "henke"
          }
        }
      ]
    }
  }
}

What version are you using? How are you ingesting synonyms? Can you reproduce the same issue using this script?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.