Skip to content

Instantly share code, notes, and snippets.

@anodoor
Created March 6, 2014 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anodoor/9386081 to your computer and use it in GitHub Desktop.
Save anodoor/9386081 to your computer and use it in GitHub Desktop.
$stores = \Model_Store::find('all');
$es = \ElasticSearch\Client::connection('http://127.0.0.1:9200/stores/store');
$es->map(array(
"store" => array(
"properties" => array(
"name" => array("type" =>"string"),
"pin" => array(
"properties" => array(
"location" => array(
"type" => "geo_point"
)
)
)
)
)
)
);
foreach ($stores as $store) {
$es->delete($store->sl_id);
$es->index(array(
'name' => 'Salon '.$store->sl_store,
'adress' => $store->sl_address." ".$store->sl_address2." ".$store->sl_zip." ".$store->sl_city. " ".$store->sl_country,
'pin' => array(
'location' => array(
"lat" => $store->sl_latitude,
"lon" => $store->sl_longitude
)
)
), $store->sl_id);
}
$es = \ElasticSearch\Client::connection('http://127.0.0.1:9200/stores/store');
$results = $es->search(array(
"query" => array(
'match_all' => array()
),
"facets" => array(
"geo1" => array(
"geo_distance" => array(
"store.pin.location" => array(
"lat" => 50.3691335,
"lon" => 3.5025972
),
"ranges" => array(
array("from" => 0, "to" => 20),
array("from" => 20, "to" => 40)
)
)
)
)
)
);
var_dump($results);
$results = $es->search(array(
"query" => array(
"filtered" => array(
"filter" => array(
"geo_distance" => array(
"distance" => "25km",
"store.pin.location" => array(
"lat" => 50.3691335,
"lon" => 3.5025972
)
)
),
"query" => array(
'match_all' => array()
)
)
)
)
);
var_dump($results);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment