进阶-第79__elasticsearch高手进阶_实战搜索距离当前位置一定范围内的酒店

 

酒店o2o app,作为案例背景

 

比如说,现在用户,所在的位置,是个地理位置的坐标,我是知道我的坐标的,app是知道的,android,地理位置api,都可以拿到当前手机app的经纬度

 

我说,我现在就要搜索出,举例我200m,或者1公里内的酒店

 

重要!!!!

 

我们之前出去玩儿,都会用一些酒店o2o app,典型的代表,很多旅游app,一般来说,我们怎么搜索,到了一个地方,就会搜索说,我这里举例几百米,2公里内的酒店,搜索一下

 

上节课讲解的,其实也很重要,一般来说,发生在我们在去旅游之前,会现在旅游app上搜索一个区域内的酒店,比如说,指定了西安火车站、西安博物馆,拿指定的几个地方的地理位置,组成一个多边形区域范围,去搜索这个区域内的酒店

 

承认,一些案例,当然不可能说达到讲解真实的复杂的大型的项目的效果来的那么好,光是学知识,学技术而言,有一些案例就非常不错了

 

后面,会讲解真正的企业级的大型的搜索引擎,真实复杂业务的数据分析系统的项目

GET /hotel_app/hotels/_search

{

  "query": {

    "bool": {

      "must": [

        {

          "match_all": {}

        }

      ],

      "filter": {

        "geo_distance": {

          "distance": "200km",//距离这个位置之内

          "pin.location": {

            "lat": 40,//纬度

            "lon": -70//经度

          }

        }

      }

    }

  }

}

结果:

{

  "took": 60,

  "timed_out": false,

  "_shards": {

    "total": 5,

    "successful": 5,

    "failed": 0

  },

  "hits": {

    "total": 1,

    "max_score": 1,

    "hits": [

      {

        "_index": "hotel_app",

        "_type": "hotels",

        "_id": "1",

        "_score": 1,

        "_source": {

          "name": "喜来登大酒店",

          "pin": {

            "location": {

              "lat": 40.12,

              "lon": -71.34

            }

          }

        }

      }

    ]

  }

}

 

 

 

GET /hotel_app/hotels/_search

{

  "query": {

    "bool": {

      "must": [

        {

          "match_all": {}

        }

      ],

      "filter": {

        "geo_distance": {

          "distance": "20km",

          "pin.location": {

            "lat": 40,

            "lon": -70

          }

        }

      }

    }

  }

}

结果:

{

  "took": 2,

  "timed_out": false,

  "_shards": {

    "total": 5,

    "successful": 5,

    "failed": 0

  },

  "hits": {

    "total": 0,

    "max_score": null,

    "hits": []

  }

}

 

猜你喜欢

转载自blog.csdn.net/qq_35524586/article/details/88676433