查询elasticsearch时没有匹配项

b1uwtaje  于 2021-06-10  发布在  ElasticSearch
关注(0)|答案(1)|浏览(367)

我在试着进行ElasticSearch。何时运行此查询

GET accounts/_search/
{
  "query": {
   "term": {
     "address_line_1": "1000"
   }
  }
}

我得到了多张像这样的唱片

"hits" : [
      {
        "_index" : "accounts",
        "_type" : "_doc",
        "_id" : "...",
        "_score" : 8.355149,
        "_source" : {
          "state_id" : 35,
          "first_name" : "...",
          "last_name" : "...",
          "middle_name" : "P",
          "dob" : "...",
          "status" : "ACTIVE",
          "address_line_1" : "1000 BROADROCK CT",
          "address_line_2" : "",
          "address_city" : "PARMA",
          "address_zip" : "",
          "address_zip_plus_4" : ""
        }
      },

但当我试图扩展它,以包括更像下面我没有得到任何匹配

GET accounts/_search/
{
  "query": {
   "term": {
     "address_line_1": "1000 B"
   }
  }
}

答案是

{
  "took" : 0,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [ ]
  }
}
23c0lvtd

23c0lvtd1#

这个 term 查询正在查找完全匹配的项。你的 address_line_* 字段很可能是用标准分析器编制索引的,标准分析器将所有字母小写,这反过来又阻止了查询的匹配。
所以要么用

GET accounts/_search/
{
  "query": {
   "match": {                <--
     "address_line_1": "1000 B"
   }
  }
}

它并不真正关心b是小写/大写,也不需要调整字段分析器以保持大写。

相关问题