title: Rails - Elasticsearch - search by coordinates with Chewy
body: <p>I'm using Elasticsearch on my Rails APP trhough <code>gem 'chewy'</code>.</p>
  <p>I have two models: Products and Tags [many to many relationship, managed through ProductTag model].</p>
  <p>I defined ProductsIndex as follow:</p>
  <pre><code>class ProductsIndex &lt; Chewy::Index
    define_type Product do
      field :name
      field :tags, value: -&gt; { tags.map(&amp;:name)}
      field :coordinates, type: 'geo_point', value: -&gt;{ {lat: lat, lon: lon} }
    end
  end
  </code></pre>
  <p>I can successfully query ProductsIndex in my controller with:</p>
  <pre><code>q = params[:q]
  @products = ProductsIndex.filter { tags(:and) == [q] }.load
  </code></pre>
  <p>which returns me all the Product objects with the specified tag.</p>
  <p>My question is: How can I query ProductIndex to return all the Product objects within a radius of 100Km from a given pair of coordinates (lat/lon)?</p>
  <p>I do not strictly need sorting by distance, but if you include it in your answer it will be greatly appreciated :)</p>
  <h1>edit</h1>
  <p>I'm trying something like this but it doesn't work:</p>
  <pre><code>ProductsIndex.filter {
    geo_distance: {    
      distance: '100km',    
      location: {        
        lat: 60.0951482712848,        
        lon: -86.4810766234584    
      }
    }
  }
  </code></pre>
  <p>I got the following syntax error</p>
  <pre><code> SyntaxError: (irb):10: syntax error, unexpected ':', expecting '}'
  ...uctsIndex.filter {geo_distance: {    distance: '100km',    l...
  ...                               ^
  </code></pre>