#查询所有
GET /hotel/_search
{
"query": {
"match_all": {}
}
}
{
"took" : 0, // 花费了多长时间
"timed_out" : false, // 是否超时
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : { //命中的数据
"total" : {
"value" : 201, //搜索到的总条数
"relation" : "eq"
},
"max_score" : 1.0, //文档的相关性得分
"hits" : [ // 文档 是个数组 一个一个文档
{
"_index" : "hotel",
"_type" : "_doc",
"_id" : "36934",
"_score" : 1.0,
"_source" : {
"address" : "静安交通路40号",
"brand" : "7天酒店",
"business" : "四川北路商业区",
"city" : "上海",
"id" : 36934,
"location" : "31.251433, 121.47522",
"name" : "7天连锁酒店(上海宝山路地铁站店)",
"pic" : "https://m.tuniucdn.com/fb2/t1/G1/M00/3E/40/Cii9EVkyLrKIXo1vAAHgrxo_pUcAALcKQLD688AAeDH564_w200_h200_c1_t0.jpg",
"price" : 336,
"score" : 37,
"starName" : "二钻"
}
}]
}
}
#全文检索
GET /hotel/_search
{
"query": {
"match": {
"all": "如家"
}
}
}
匹配度越高,排名越靠前
GET /hotel/_search
{
"query": {
"multi_match": {
"query": "7天",
"fields": ["name","brand","city"]
}
}
}
查询的字段越多,搜索的速度越慢,推荐使用copy到同一个字段中进行查询
精确查询,查询字段不能分词,并且是与查询字段完全匹配
#精确查询
#term 根据词条精确查询
#range 根据值的范围查询
GET /hotel/_search
{
"query": {
"term": {
"city": {
"value": "北京"
}
}
}
}
GET /hotel/_search
{
"query": {
"range": {
"price": {
"gte": 100,
"lte": 1000
}
}
}
}
地理查询
#地理查询
#查询附件的坐标点
GET /hotel/_search
{
"query": {
"geo_distance":{
"distance" : "15km",
"location" : "31.21,121.5"
}
}
}
复合查询
GET /hotel/_search
{
"query": {
"function_score": {
"query": {
"match": {
"all": "外滩"
}
},
"functions": [
{
"filter": {
"term": {
"id": "1"
}
},
"weight": 10
}
],
"boost_mode": "multiply"
}
}
}
GET /hotel/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "如家"
}
}
],
"must_not": [
{
"range": {
"price": {
"gt": 400
}
}
}
],
"filter": [
{
"geo_distance": {
"distance": "15km"
, "location": {
"lat": 31.21,
"lon": 121.5
}
}
}
]
}
}
}