Comments (4)
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.
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.
@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.
Would be happy to see this feature implemented.
from laravel-scout-elastic.
Related Issues (20)
- lumen8 use paginate error, HOT 3
- How to perform advanced customisation? HOT 1
- Warning about type deprecation HOT 10
- All data doesn't get indexed and no error pops up when importing HOT 1
- index not found exception HOT 3
- When i fetch data from elastic its give error like this "no handler found for uri" HOT 1
- Laravel Scout 9. please? HOT 1
- Please add php 8 suport HOT 1
- Make it work with ES 7 HOT 3
- Make it work with ES 7 HOT 1
- ElasticClient namespace incompatible HOT 6
- Change namespace HOT 1
- _ide_helper.php should not be part of the packet HOT 1
- 小建议 HOT 1
- laravel9安装失败了 HOT 1
- '_index' => $model->searchableAs(), '_type' => get_class($model), HOT 1
- Class "ScoutEngines\Elasticsearch\ElasticsearchProvider" not found - Laravel 9 HOT 1
- ->forceDelete() on Model, don't delete on elasticsearch
- Please install the Elasticsearch PHP client: elasticsearch/elasticsearch but is installed HOT 1
- after 7.0 ,only 'index', delete 'Type'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-scout-elastic.