为什么这个术语查询没有返回任何结果?

时间:2016-12-22 15:14:16

标签: elasticsearch elasticsearch-5

我目前正在弹性搜索中实现一个简单的人物搜索。我做了一些研究,发现了很多关于如何实现全文搜索等功能的内容。

问题是,有些查询不会返回任何结果。

我有以下索引模板:

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"
            }
         }
      }
   }
}

我的查询如下所示:

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

如果我现在搜索,例如因为" Maria"然后我得到一个结果。但如果我正在搜索zipCode(例如12345)而不是我没有得到任何结果。

analyze api有以下回应:

  "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
        }
     ]
  }

}

我没有得到任何回复。我已经尝试了术语,并匹配查询和所有其他类型的东西,但我无法使其正常工作?

所需文件:

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

0 个答案:

没有答案