elasticsearch的rest api练习记录

GET _search
{
   "query": {
      "match_all": {}
   }
}


PUT  /blog/article/1
{
    "title":"my sense",
    "author":"syj",
    "content":"sense is a good tool"
}

DELETE /blog/arcticle/1

GET /blog/article/1

GET  /blog/article/_search
{
    "query":{
        "query_string": {
            "query": "sense"
        }
    }
    
}

GET  /blog/article/_search
{
    "query":{
        "query_string": {
           "fields": ["id"],
           "query": 1
        }
    }
    
}

DELETE /attractions

PUT /attractions
{
    "mappings": {
        "city":{
            "properties":{
                "city":{"type":"string"},
                "state":{"type":"string"},
                "location":{"type":"geo_point"}
            }
        }
    }
}

GET /attractions/_search

POST /attractions/city/1
{
    "city":"Beijing",
    "state":"BJ",
    "location":{
        "lat":"39.91667",
        "lon":"116.41667"
    }
}

POST /attractions/city/2
{
    "city":"ShangHai",
    "state":"SH",
    "location":{
        "lat":"34.50000",
        "lon":"121.43333"
    }
}

POST /attractions/city/3
{
    "city":"XiaMen",
    "state":"XM",
    "location":{
        "lat":"24.08333",
        "lon":"118.10000"
    }
}

POST /attractions/city/4
{
    "city":"FuZhou",
    "state":"FZ",
    "location":{
        "lat":"26.08333",
        "lon":"119.30000"
    }
}

POST /attractions/city/5
{
    "city":"GuangZhou",
    "state":"GZ",
    "location":{
        "lat":"23.16667",
        "lon":"113.23333"
    }
}


GET /attractions/city/_search



GET /attractions/city/_search
{
   "query": {
       "bool": {
           "must":{
               "match_all": {}             
           },
           "filter":{
               "geo_distance": {
                  "distance": "500km",
                  "location": {
                     "lat": 24.46667,
                     "lon": 118.10000
                  }
               }
           }
            
       }
   }
}

GET /attractions/city/_search
{
    "query": {
        "geo_distance": {
            "distance": "500km",
            "location": {
                "lat": 24.46667,
                 "lon": 118.10000
            }
       }        
   }
}
 
 
GET /attractions/city/_search
{
   "query": {
       "bool": {
           "must":{
               "match_all": {}             
           },
           "filter":{
               "geo_bounding_box": {
                  "location": {
                     "top_left": {
                        "lat": 39.91667,
                        "lon": 116.41667
                     },
                     "bottom_right": {
                        "lat": 24.46667,
                        "lon": 118.10000
                     }
                  }
               }
           }
            
       }
   }
}
 
 

 
GET /attractions/city/_search
{
   "query": {
       "bool": {
           "must":{
               "match_all": {}             
           },
           "filter":{
               "geo_distance_range": {
                  "from": "100km",
                  "to": "200km",
                  "location": {
                     "lat": 40.46667,
                     "lon": -73.809
                  }
               }
           }
            
       }
   }
}



GET /attractions/city/_search
{
    "from": 0,
    "size": 1,
    "sort": [
       {
          "_geo_distance": {
             "location": {
                 "lat": 39.91667,
                 "lon": 116.41167
             },
             "order": "asc",
             "unit": "km"
          }
       }
    ],
   "query": {
       "bool": {
           "must":{
               "match_all": {}             
           }
       }
   }
}


GET /attractions/city/_search
{
   "query": {
       "bool": {
           "must":{
               "match_all": {}             
           },
           "filter":{
               "geo_distance": {
                  "distance": "500km",
                  "location": {
                     "lat": 24.46667,
                     "lon": 118.10000
                  }
               }
           }
            
       }
   },
   "aggs": {
       "per_ring": {
           "geo_distance": {
               "field": "location",
               "unit": "km",
               "origin": {
                   "lat": 24.46667,
                   "lon": 118.10000
               },
               "ranges":[
                   {"from": 0,"to": 500},
                   {"from": 500,"to": 8000}
                ]  
           }
       }
   }
   
}





GET /attractions/city/_search
{
   "query": {
       "bool": {
           "must":{
               "match_all": {}             
           },
           "filter":{
               "geo_distance": {
                  "distance": "10000km",
                  "location": {
                     "lat": 24.46667,
                     "lon": 118.10000
                  }
               }
           }
            
       }
   },
   "aggs": {
       "grid_agg": {
           "geohash_grid": {
               "field": "location",
               "precision": 2
               
           }
       }
   }
   
}




GET /attractions/city/_search
{
   "query": {
       "bool": {
           "must":{
               "match_all": {}             
           },
           "filter":{
               "geo_distance": {
                  "distance": "10000km",
                  "location": {
                     "lat": 24.46667,
                     "lon": 118.10000
                  }
               }
           }
            
       }
   },
   "aggs": {
       "map-zoom": {
           "geo_bounds": {
               "field": "location"
           }
       }
   }
   
}








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Soyoger

听说打赏的都进了福布斯排行榜。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值