Book Image

ElasticSearch Cookbook

By : Alberto Paro
Book Image

ElasticSearch Cookbook

By: Alberto Paro

Overview of this book

Table of Contents (20 chapters)
ElasticSearch Cookbook Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Using a geo bounding box filter


One of the most common operations in geolocalization is searching for a box (square).

Getting ready

You need a working ElasticSearch cluster and an index populated with the GeoScript chapter_05/geo/populate_geo.sh, available in the code bundle for this book.

How to do it...

A search to filter documents related to a bounding box (40.03, 72.0) and (40.717, 70.99) can be done with a similar query:

curl -XGET http://127.0.0.1:9200/test-mindex/_search?pretty -d '{
  "query": {
    "filtered": {
      "filter": {
        "geo_bounding_box": {
          "pin.location": {
            "bottom_right": {
              "lat": 40.03,
              "lon": 72.0
            },
            "top_left": {
              "lat": 40.717,
              "lon": 70.99
            }
          }
        }
      },
      "query": {
        "match_all": {}
      }
    }
  }
}'

How it works...

ElasticSearch has a lot of optimization options to search for a box shape. The latitude and longitude...