Edge Ngram not working with digits

Hi,

So I'm trying to build search-as-you-type and this is my mapping:

PUT patients
{
  "settings": {
    "analysis": {
      "analyzer": {
        "autocomplete": {
          "tokenizer": "autocomplete",
          "filter": [
            "lowercase"
          ]
        },
        "autocomplete_search": {
          "tokenizer": "lowercase"
        }
      },
      "tokenizer": {
        "autocomplete": {
          "type": "edge_ngram",
          "min_gram": 2,
          "max_gram": 10,
          "token_chars": [
            "letter","digit","symbol","whitespace"
          ]
        }
      }
    }
  },
  "mappings": {
    "db": {
      "properties": {
        "FirstName": {
          "type": "text",
          "analyzer": "autocomplete",
          "search_analyzer": "autocomplete_search"
        },
        "LastName": {
          "type": "text",
          "analyzer": "autocomplete",
          "search_analyzer": "autocomplete_search"
        },
        "PreferredName": {
          "type": "text",
          "analyzer": "autocomplete",
          "search_analyzer": "autocomplete_search"
        },
        "DateOfBirth": {
          "type": "text",
          "analyzer": "autocomplete",
          "search_analyzer": "autocomplete_search"
        },
        "PMRecordNumber": {
          "type": "text",
          "analyzer": "autocomplete",
          "search_analyzer": "autocomplete_search"
        }
      }
    }
  }
}

PMRecordnumber is alphanumeric string, eg: "PH100304", "PH105302" etc.
So when I'm trying to search this:

 GET patients/_search
{
  "explain": true, 
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "PH1003",
            "fields": ["FirstName", "LastName", "DateOfBirth", "PMRecordNumber"]
            , "type": "cross_fields"
          }
        }
      ]
    }
  }
}

So it is giving results with last name = "Phy" and it is not scoring based on PMRecordnumber.

I believe the "lowercase" tokenizer is dropping the digits out, so how am is supposed to go about this?

1 Like

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