1. 精确查询
(1)一般是查找keyword,数值,日期,boolean等类型字段,所以不会对搜索条件分词,常见的有:term,range
//只查询city=南京市鼓楼区,且不会对搜索词分词
get /hotel/_search
{"query":{"term": {"city": {"value": "南京市鼓楼区"}}}
}
查询结果:
{"took" : 0,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 1,"relation" : "eq"},"max_score" : 1.2039728,"hits" : [{"_index" : "hotel","_type" : "_doc","_id" : "4","_score" : 1.2039728,"_source" : {"address" : "是单独发2号","brand" : "四季如春","business" : "新街口商圈","city" : "南京市鼓楼区","id" : 4,"location" : "66.66,133.36","name" : "四季如春","pic" : "http://www.qiniu.com/images/xxx.png","price" : 999,"score" : 9,"starName" : "五星"}}]}
}
range查询
get /hotel/_search
{"query":{"range": {"price": {"gte": 400,"lte": 1000}}}
}
范围结果:
{"took" : 0,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 2,"relation" : "eq"},"max_score" : 1.0,"hits" : [{"_index" : "hotel","_type" : "_doc","_id" : "3","_score" : 1.0,"_source" : {"address" : "洪武北路1号","brand" : "四季","business" : "新街口商圈","city" : "南京市玄武区","id" : 3,"location" : "33.35,131.36","name" : "四季","pic" : "http://www.bai.com/images/7.png","price" : 489,"score" : 8,"starName" : "3星"}},{"_index" : "hotel","_type" : "_doc","_id" : "4","_score" : 1.0,"_source" : {"address" : "是单独发2号","brand" : "四季如春","business" : "新街口商圈","city" : "南京市鼓楼区","id" : 4,"location" : "66.66,133.36","name" : "四季如春","pic" : "http://www.qiniu.com/images/xxx.png","price" : 999,"score" : 9,"starName" : "五星"}}]}
}