elasticsearch 查询:match查询

1. match查询
match查询属于高层查询,会根据查询内容不一样,采用不同的查询方式。
  • 查询的内容如果是日期或者数值,会将你基于的字符串查询内容转换为日期或者数值对待;
  • 如果查询的内容是一个不能被分词的内容(keyword),match查询不会将指定的关键字分词;
  • 如果查询内容是一个可以被分词的内容(text),match会将指定的查询内容根据一定方式去分词,去分词库中匹配指定内容;
match查询,实际底层就是多个term查询,将多个term查询的结果封装到一起。
#测试--match查询:address字段是text类型,查询address包含成都市的数据
POST /king_test_person/_search
{
  "query": {
    "match": {
      "address": "成都市"        
    }
  }
}

  

2. match_all查询
查询全部内容,不指定任何查询条件。
#测试--match_all查询
POST /king_test_person/_search
{
  "from": 0, 
  "size": 20, 
  "query": {
    "match_all": {}
  }
}

 

3.布尔match查询

基于一个field匹配的内容,采用and或者or的方式连接
#测试--布尔match:查询address 包含四川省并且包含成都市的
POST /king_test_person/_search
{
  "query": {
    "match": {
      "address": {
        "query": "四川省 成都市",
        "operator": "and"
      }
    }
  }
}

#测试--布尔match:查询address 包含四川省或者成都市
POST /king_test_person/_search
{
  "query": {
    "match": {
      "address": {
        "query": "四川省 成都市",
        "operator": "or"
      }
    }
  }
}
 
4. multi_match查询
match真对一个field做检索,multi_match针对多个field进行检索,多个field对应一个text。
#测试--multi_match查询:查询address,introduce 匹配湖南省的数据
POST /king_test_person/_search
{
  "query": {
    "multi_match": {
      "query": "湖南省",                   #指定text
      "fields": ["address","introduce"]   #指定field列表
    }
  }
}
posted @ 2024-01-30 08:24  king_wq_庆  阅读(128)  评论(0编辑  收藏  举报