Last active
July 5, 2016 17:56
-
-
Save elchele/e8c9e65afa63f15d9644 to your computer and use it in GitHub Desktop.
PHP script for simple querying of Elasticsearch using Sugar default server settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Author: Angel Magaña - [email protected] | |
* File: <sugar_root>/es_test.php | |
* | |
* Executes simple Elasticsearch query using | |
* Elasticsearch params from Sugar config files | |
* Usage: http://<sugar_url>/es_test.php?term=<your_search_term> | |
* | |
*/ | |
//Set params | |
require_once('config.php'); | |
require_once('config_override.php'); | |
$index = $sugar_config['unique_key'] . '_shared'; | |
$host = $sugar_config['full_text_engine']['Elastic']['host']; | |
$port = $sugar_config['full_text_engine']['Elastic']['port']; | |
$term = $_GET['term']; | |
$url = 'http://' . $host . ':' . $port . '/' . $index . '/_search?q=' . $term . '&size=100'; | |
//cURL Request | |
$cu = curl_init(); | |
curl_setopt($cu, CURLOPT_URL, $url); | |
curl_setopt($cu, CURLOPT_HEADER, 0); | |
curl_setopt($cu, CURLOPT_RETURNTRANSFER, 1); | |
$result = curl_exec($cu); | |
curl_close($cu); | |
$result = json_decode($result); | |
$all = $result->hits->hits; | |
foreach($all as $one) | |
{ | |
$record = (array) $one->_source; | |
echo 'Module: ' . $record['module'] . '<br/>Name: ' . $record['name'] . '<p>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment