第一章第十一节:Elasticsearch之term查询

term:精确查询,适合检索非text类型的字段,比如keyword 、numeric、date
match:适合检索text类型的字段

1、term查询

#term的query查询
GET /bank/_search
{
  "query": {
    "term": {
      "age": 28
    }
  }
}

#term的组合查询
GET /bank/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "age": {
              "value": "28"
            }
          }
        }
      ]
    }
  }
}

2、term对text类型的精确查询

对比match_phrase短语查询:
1:term可以通过查询text字段的keyword,进行精确匹配,需要完全匹配,而且该字段必须要有keyword类型才可以
比如:"name": {"type":"text","fields": {"keyword":{"type":"keyword"}}},
2:match_phrase进行精确匹配,只要包含就可以返回结果
#term精确匹配
GET /bank/_search
{
  "query": {
    "term": {
      "firstname.keyword": "Nanette"
    }
  }
}

#match_phrase短语匹配
GET /bank/_search
{
  "query": {
    "match_phrase": {
      "firstname": "Nanette"
    }
  }
}
posted @ 2021-07-04 14:27  努力的校长  阅读(334)  评论(0编辑  收藏  举报