Why is this term query not returning any results?

167 views Asked by At

I am currently implementing a simple person search in elastic search. I did some research and found quite a lot content about how to implement features as full text search and so on.

The problem is, that some queries just don't return any results.

I have the following index template:

PUT /_template/template_hca_bp
{
   "template": "test",
   "settings": {
      "analysis": {
         "filter": {
            "autocomplete_filter": {
               "type": "ngram",
               "min_gram": 3,
               "max_gram": 10
            }
         },
         "analyzer": {
            "autocomplete": {
               "type": "custom",
               "tokenizer": "standard",
               "filter": [
                  "lowercase",
                  "autocomplete_filter"
               ]
            },
            "search_ngram": {
               "type": "custom",
               "tokenizer": "lowercase",
               "filter": [
                  "lowercase"
               ]
            }
         }
      }
   },
   "mappings": {
      "persons": {
         "properties": {
            "address": {
               "properties": {
                  "city": {
                     "type": "text",
                     "search_analyzer": "standard",
                     "analyzer": "autocomplete"
                  },
                  "countryCode": {
                     "type": "keyword"
                  },
                  "doorNumber": {
                     "type": "keyword"
                  },
                  "id": {
                     "type": "text",
                     "index": "no",
                     "include_in_all": false
                  },
                  "stairwayNumber": {
                     "type": "keyword"
                  },
                  "street": {
                     "type": "text",
                     "analyzer": "autocomplete",
                     "search_analyzer": "standard"
                  },
                  "streetNumber": {
                     "type": "keyword"
                  },
                  "zipCode": {
                     "type": "keyword"
                  }
               }
            },
            "id": {
               "type": "keyword",
               "index": "no",
               "include_in_all": false
            },
            "name": {
               "type": "text",
               "analyzer": "autocomplete",
               "search_analyzer": "standard",
               "boost":2
            },
            "personType": {
               "type": "keyword",
               "index": "no",
               "include_in_all": false
            },
            "title": {
               "type": "text"
            }
         }
      }
   }
}

My query looks like the following:

POST test/_search
{
   "query": {
      "multi_match": {
         "query": "Maria",
         "type":"cross_fields",
         "fields": [
            "name^2", "city", "street", "streetNumber", "zipCode"
         ]
      }
   }
}

If I now search e.g. for "Maria" then I get a result. But if I'm searching for a zipCode (e.g. 12345) than I don't get any result.

The analyze api has the following response:

  "detail": {
  "custom_analyzer": false,
  "analyzer": {
     "name": "default",
     "tokens": [
        {
           "token": "12345",
           "start_offset": 0,
           "end_offset": 5,
           "type": "<NUM>",
           "position": 0,
           "bytes": "[31 32 33 34 35]",
           "positionLength": 1
        }
     ]
  }

}

I'm not getting any response. I have tried term, and match queries and all other kind of stuff, but I can't get it working?

The desired document:

"id": "V2718984F3A0ADA95176424457A068F9DC93FC8BDA0898A4E8248F194AE1AF4FCE04C29F46367DDEC33721C15C2679B7BB",
"name": "Maria Smith",
"personType": "APO",
"address": {
  "countryCode": "A",
  "city": "Testcity",
  "zipCode": "12345",
  "street": "Avenue",
  "streetNumber": "2"
}
0

There are 0 answers