Giter VIP home page Giter VIP logo

Comments (4)

xcaptain avatar xcaptain commented on May 27, 2024 2

I wrote simple example to do geo query.

Model::search('some text', function ($engine, $query, $options) {
    $options['body']['query']['bool']['filter']['geo_distance'] = [
        'distance' => '1000km',
        'location' => ['lat' => 36, 'lon' => 111],
    ];
    return $engine->search($options);
})->get()->toArray();

it works for me, ping @ErickTamayo
@sandervanhooft As you said, I created a mapping that has geo_location and then use scout:import to import data into ES.

curl -XPUT 'http://localhost:9200/some_index/_mapping/some_type' -d '
{
  "properties": {
    "location": {
      "type": "geo_point"
    }
  }
}
'

from laravel-scout-elastic.

zanematthew avatar zanematthew commented on May 27, 2024 1

To add for others, you can easily add sorting as well. Just to add for any others that stumble across this. Its fairly easy to set this up based on the ES docs.

Model::search('some text', function ($engine, $query, $options) {
    $options['body']['query']['bool']['filter']['geo_distance'] = [
        'distance' => '1000km',
        'location' => ['lat' => 36, 'lon' => 111],
    ];
    $options['body']['sort']['_geo_distance'] = [
            'latlon'        => '39.290385,-76.612189', // This is your field that contains the lat/long
            'order'         => 'desc',
            'unit'          => 'km',
            'mode'          => 'min',
            'distance_type' => 'arc',
    ];
    return $engine->search($options);
})->get()->toArray();

@xcaptain what you have is an ideal solution. Do you know if there are any issues with search and not passing in a string, say if you want to only search based on geolocation. I've tried Foo::search('', function(..., and results do appear to display correctly, I'm just wondering if using '' would cause issues down the road.

from laravel-scout-elastic.

ErickTamayo avatar ErickTamayo commented on May 27, 2024

@sandervanhooft as the linked discussion we might need to extend at some point the Scout Query Builder class, I am planning to do so but not right now.

Probably in the next month will have some free time to extend the most common ES features.

from laravel-scout-elastic.

xcaptain avatar xcaptain commented on May 27, 2024

Would be happy to see this feature implemented.

from laravel-scout-elastic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.