match-phrase-prefix-query-on-an-embedded-text-field

101 views Asked by At

Versions (relevant - OpenSearch/Dashboard/Server OS/Browser): opensearch: latest (2.7) opensearch-dashboards: latest

Describe the issue: I’m trying to execute the below match_phrase_prefix query and I don’t see any results. however, when I run match_phrase query on the same index, I see two hits. Wondering how index_prefixes works on embedded fields. Any help here would be appreciated.

Match Phrase Prefix query
{
  "query": {
    "bool":{
      "filter": [
    {
      "bool": {
        "must": [
          {
        "match_phrase_prefix": {
          "applications.name": "bind-lib"
        }
          }
        ]
      }
    }
      ]
     }
   }
}

Match Phrase query
{
  "query": {
    "bool":{
      "filter": [
    {
      "bool": {
        "must": [
          {
        "match_phrase": {
          "applications.name": "bind-libs"
        }
          }
        ]
      }
        }
      ]
    }
  }
}
Below is the mapping of my index
{
  "mappings": {
    "properties": {
    "platform_name": { 
        "type": "text",
        "index_prefixes": { }
    },
    "applications":  {
        "properties": {
            "name": { "type": "text", "index_prefixes": { } },
            "app_version": { "type": "keyword" },
            "publisher": { "type": "text" }
         }
       }
      }
    }
  }
}
{
    "platform_name": "Red Hat",
    "applications": [
        {   "name": "red18", "version": "v2", "publisher": "red brown ltd"},
        {   "name": "bind-libs", "version": "v1", "publisher": "red brown ltd"},
        {   "name": "python-libs", "version": "v1", "publisher": "red brown ltd"},
        {   "name": "python1-libs", "version": "v1", "publisher": "red brown ltd"},
        {   "name": "python2-libs", "version": "v1", "publisher": "red brown ltd"},
        {   "name": "python3-libs", "version": "v1", "publisher": "red brown ltd"},
        {   "name": "python4-libs", "version": "v1", "publisher": "red brown ltd"},
        {   "name": "python5-libs", "version": "v1", "publisher": "red brown ltd"},
        {   "name": "python6-libs", "version": "v1", "publisher": "red brown ltd"},
        {   "name": "python7-libs", "version": "v1", "publisher": "red brown ltd"}      
    ],
}

I tried to verify if OpenSearch was generating the correct lucene query and it looks right

{"_shards":{"total":1,"successful":1,"failed":0},"valid":true,"explanations":[{"index":"ec2resources","valid":true,"explanation":"+(ConstantScore(spanNear([apps.name:bind, mask(apps.name._index_prefix:lib) as apps.name], 0, true)))^0.0 #FieldExistsQuery [field=_primary_term]"}]}[ec2-user@ip-10-0-29-126 ~]$

One thing I noticed is if the entry I'm searching for is the first one in the embedded array, phrase_prefix returns the document. However, if the entry is not the first one, phrase_prefix does not return any hits.

0

There are 0 answers