Search as you type datatype and Multi Match Search with Filter

Hello,

My mapping is below (Elasticsearch version 7.4.1):

PUT /test
  {
  "mappings": {
    "properties": {
       "countryCd": {
        "type": "text"
      },
      "langSetId": {
        "type": "long"
      },
      "subdivName": {
        "type": "search_as_you_type",
        "analyzer": "hindi",
        "max_shingle_size": 3
      }
   }
   }
   }

Data is inserted as below:

PUT test/_doc/1?refresh
{
  "countryCd": "IN",
  "langSetId": 1,
  "subdivName": "Maharashtra"
}

PUT test/_doc/2?refresh
{
  "countryCd": "IN",
  "langSetId": 1,
  "subdivName": "Madhya Pradesh"
}

PUT test/_doc/3?refresh
{
  "countryCd": "IN",
  "langSetId": 1,
  "subdivName": "Gujarat"
}

PUT test/_doc/4?refresh
{
  "countryCd": "IN",
  "langSetId": 2,
  "subdivName": "Maharashtra-Hindi"
}

PUT test/_doc/5?refresh
{
  "countryCd": "IN",
  "langSetId": 2,
  "subdivName": "Madhya Pradesh-Hindi"
}

PUT test/_doc/6?refresh
{
  "countryCd": "IN",
  "langSetId": 2,
  "subdivName": "Gujarat-Hindi"
}

PUT test/_doc/7?refresh
{
  "countryCd": "US",
  "langSetId": 1,
  "subdivName": "Massachusetts"
}

Now if I use the below query and filter on the long field, I am getting the results correctly:

GET test/_search
{
  "query": {
    "bool": {
      "must": {
        "multi_match": {
          "query": "ma",
          "type": "bool_prefix",
          "fields": [
            "subdivName"
          ]
        }
      },
      "filter": [
            {"term": {
             "langSetId": 1
            }}
            ]
          }
      }  
      }
    }
  }
}

However, if I try to filter on the text field, I am not getting any results:

GET test/_search
{
  "query": {
    "bool": {
      "must": {
        "multi_match": {
          "query": "ma",
          "type": "bool_prefix",
          "fields": [
            "subdivName"
          ]
        }
      },
      "filter": [
            {"term": {
             "countryCd":"IN"
            }}
            ]
          }
      }  
      }
    }
  }
}

Why is adding the the text field in the filter clause not returning any results? Any help appreciated.

Thanks in advance!

Try with:

"countryCd":"in"

Thanks. :flushed:

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