Edge-ngram not working for single edge case!

My edge-ngram solution does not return any results for the following search:

"10th A"

Where 3 documents exist with the field values:

  "10th Avenue, Red Beach, New Zealand",
  "4 10th Avenue, Red Beach, New Zealand",
  "2 10th Avenue, Red Beach, New Zealand"

Query:

POST /addresses_nz/_search?pretty
{
  "_source": [
    "search_name"
  ],
  "size": 10, 
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "search_name.autocomplete": {
              "query": "10th A",
              "operator": "and",
              "fuzziness": 0
            }
          }
        }
      ],
      "should": [
        {
          "prefix": {
            "search_name.exact": {
              "value": "10th A"
            }
          }
        }
      ]
    }
  }
}

Index Mappings:

{
  "addresses_nz" : {
    "mappings" : {
      "properties" : {
        "search_name" : {
          "type" : "text",
          "fields" : {
            "autocomplete" : {
              "type" : "text",
              "analyzer" : "autocomplete_index",
              "search_analyzer" : "autocomplete_search"
            },
            "exact" : {
              "type" : "keyword"
            }
          }
        }
      }
    }
  }
}

Index Settings:

{
  "addresses_nz" : {
    "settings" : {
      "index" : {
        "analysis" : {
          "filter" : {
            "english_stopwords" : {
              "type" : "stop",
              "stopwords" : "_english_"
            }
          },
          "analyzer" : {
            "autocomplete_index" : {
              "filter" : [
                "lowercase",
                "english_stopwords"
              ],
              "type" : "custom",
              "tokenizer" : "autocomplete_index"
            },
            "autocomplete_search" : {
              "tokenizer" : "standard"
            }
          },
          "tokenizer" : {
            "autocomplete_index" : {
              "token_chars" : [
                "digit",
                "letter"
              ],
              "min_gram" : "1",
              "type" : "edge_ngram",
              "max_gram" : "15"
            }
          }
        }
      }
    }
  }
}

You have different search and index time analyzers, which I suspect explain what you are seeing. Run the indexed string through the index time analyzer using the analyze API and then run the search string through the same API using the search time analyzer. If you compare the results I believe you will see that the tokens do not match up, e.g. there are no edge ngram token generated by the search time analyzer to match against the index.

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