本文整理汇总了PHP中Elasticsearch\Client类的典型用法代码示例。如果您正苦于以下问题:PHP Client类的具体用法?PHP Client怎么用?PHP Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: main
public function main(Request $req, Application $app)
{
$client = new Client();
$params = array('index' => 'hrqls', 'type' => 'houseData', 'body' => ['from' => 0, 'size' => 100, 'filter' => array('range' => array('avgHomeValueIndex' => array('gte' => 0))), 'query' => ['match' => ['state' => 'Virginia']]]);
$results = $client->search($params)['hits']['hits'];
$responseObject = [];
$averageHouseValue = array('total' => 0, 'number' => 0);
$averageTurnover = array('total' => 0, 'number' => 0);
$maxHouseValue = 0;
$minHouseValue = 900000;
foreach ($results as $zip) {
$averageHouseValue['total'] += $zip['_source']['avgHomeValueIndex'];
$averageHouseValue['number']++;
$averageTurnover['total'] += $zip['_source']['turnoverWithinLastYear'];
$averageTurnover['number']++;
if ($zip['_source']['avgHomeValueIndex'] > $maxHouseValue) {
$maxHouseValue = $zip['_source']['averageHouseValue'];
}
if ($zip['_source']['averageHouseValue'] < $minHouseValue) {
$minHouseValue = $zip['_source']['averageHouseValue'];
}
}
$averageHouse = $averageHouseValue['total'] / $averageHouseValue['number'];
$averageTurn = $averageTurnover['total'] / $averageTurnover['number'];
$slidervalue = $req->get('slidervalue');
foreach ($results as $zip) {
$sliderInfo = $this->calculate($slidervalue);
$weight = $this->determineWeight($sliderInfo, $zip['_source']['avgHomeValueIndex'], $averageHouse, $maxHouseValue, $minHouseValue);
$responseObject[] = array('lat' => $zip['_source']['location']['lat'], 'lon' => $zip['_source']['location']['lon'], 'weight' => $weight);
}
return new Response(json_encode($responseObject), 200);
}
示例2: create
public function create()
{
$elasticsearch = new Client();
$sight = $this->sightRepository->getById(Input::get('sight_id'));
$time = Carbon::now($sight->city->timezone)->hour;
$searchQuery['index'] = 'sightseeing';
$searchQuery['type'] = 'sight';
$searchQuery['body'] = ['min_score' => 0.0001, 'query' => ['function_score' => ['query' => ['bool' => ['must' => [0 => ['range' => ['cost' => ['lte' => Input::get('cost')]]]], 'should' => [0 => ['range' => ['closing_hours' => ['gte' => $time]]], 1 => ['range' => ['opening_hours' => ['lte' => $time]]]]]], 'functions' => [0 => ['gauss' => ['location' => ['origin' => $sight->latitude . ',' . $sight->longitude, 'offset' => '0.5km', 'scale' => '0.1km', 'decay' => 0.33]]]]]]];
$suggestions = $elasticsearch->search($searchQuery);
$filteredSuggestions = array();
$filteredSuggestions['data'] = [];
foreach ($suggestions['hits']['hits'] as $suggestion) {
$suggestionAdded = false;
foreach ($suggestion['_source']['categories'] as $category) {
if (in_array($category['id'], Input::get('categories')) && !$suggestionAdded && $suggestion['_id'] != Input::get('sight_id')) {
$filteredSuggestions['data'][] = ['id' => $suggestion['_id'], 'score' => $suggestion['_score']];
$suggestionAdded = true;
}
}
}
$maxScore = 0;
foreach ($filteredSuggestions['data'] as $suggestion) {
if ($suggestion['score'] > $maxScore) {
$maxScore = $suggestion['score'];
}
}
$filteredSuggestions['max_score'] = $maxScore;
return $filteredSuggestions;
}
示例3: handle
/**
* Handle index creation command
*
* @param Client $client
* @param string $index
*/
public function handle(Client $client, $index)
{
$config = $this->configurationRepository->get($index);
if (null === $config) {
throw new \InvalidArgumentException();
}
$client->indices()->create(['index' => $index, 'body' => $config]);
}
示例4: search
/**
* 查询 结果
*
* @param string $index 索引
* @param string $type 类型
* @param string $body 查询字符串
* @param array $attrs 额外查询参数
*
* @return mixed
*/
public function search($index, $type, $body, $attrs = [])
{
$query = ['index' => $index, 'type' => $type, 'body' => $body];
if (!empty($attrs)) {
$query = array_merge($attrs, $query);
}
return $this->esClient->search($query);
}
示例5: handle
/**
* Handle index creation command
*
* @param Client $client
* @param string $index
*/
public function handle($client, $index)
{
$config = $this->configurationRepository->get($index);
if (null === $client || null === $config) {
throw new \InvalidArgumentException();
}
$client->indices()->putSettings(['index' => $index, 'body' => ['settings' => $this->extractSettings($config)]]);
}
示例6: handle
/**
* Handle index creation command
*
* @param Client $client
* @param string $index
*/
public function handle(Client $client, $index, $type)
{
$config = $this->configurationRepository->get($index);
if ($this->isInvalid($config, $type)) {
throw new \InvalidArgumentException();
}
$client->indices()->putMapping(['index' => $index, 'type' => $type, 'body' => [$type => $config['mappings'][$type]]]);
}
示例7: testCall
/**
* @covers Fabfuel\Prophiler\Decorator\Elasticsearch\ClientDecorator::__call
*/
public function testCall()
{
$payload = ['lorem' => 'ipsum'];
$benchmark = $this->getMock('Fabfuel\\Prophiler\\Benchmark\\BenchmarkInterface');
$this->client->expects($this->once())->method('get')->with($payload);
$this->profiler->expects($this->once())->method('start')->with('ElasticMock::get', [$payload], 'Elasticsearch')->willReturn($benchmark);
$this->profiler->expects($this->once())->method('stop')->with($benchmark);
$this->decorator->get($payload);
}
示例8: addDocuments
public static function addDocuments(\ElasticSearch\Client $client, $num = 3, $tag = 'cool')
{
$options = array('refresh' => true);
while ($num-- > 0) {
$doc = array('title' => "One cool document {$tag}", 'rank' => rand(1, 10));
$client->index($doc, $num + 1, $options);
}
return $client;
}
示例9: executeByElasticClient
/**
* Execute the request by elasticsearch client
*
* @param Client $client
* @return ResponseInterface
*/
public function executeByElasticClient(Client $client)
{
$responseClass = $this->getResponseClassOfRequest();
/** @var IndexResponseInterface $response */
$response = new $responseClass();
$rawResult = RawResponse::build($client->index($this->toElasticClient()));
$response = $response->build($rawResult);
$this->getDocument()->setId($response->id());
return $response;
}
示例10: executeByElasticClient
/**
* Execute the request by elasticsearch client
*
* @param Client $client
* @return ResponseInterface
*/
public function executeByElasticClient(Client $client)
{
$params = $this->toElasticClient();
$responseClass = $this->getResponseClassOfRequest();
/** @var GetResponseInterface $response */
$response = new $responseClass();
$result = RawResponse::build($client->get($params));
if (null !== $this->document) {
$response->setDocument($this->document);
}
$response->build($result);
return $response;
}
示例11: index
/**
* @Route("/")
* @Template("DashboardMainBundle:Default:index.html.twig")
*/
public function index()
{
$params = array();
$params['hosts'] = array('127.0.0.1:9200');
$client = new Elasticsearch\Client($params);
$params = array("index" => "dash-mail-*", "type" => "mail", "body" => array("query" => array("filtered" => array("filter" => array("bool" => array("must" => array(array("missing" => array("field" => "flags")), array("term" => array("folderFullName" => "INBOX")))))))));
$results_mail = $client->search($params);
$params = array("index" => "dash-rss-*", "type" => "page");
$results_rss = $client->count($params);
$params = array("index" => "dash-twitter-*", "type" => "status");
$results_twitter = $client->count($params);
return array("mail_unread" => $results_mail['hits']['total'], "rss_total" => $results_rss['count'], "twitter_total" => $results_twitter['count']);
}
示例12: findProducts
public function findProducts(ListingFilter $filter)
{
$must = [];
if ($filter->getEshop() !== null) {
$must[] = ["term" => [ProductMeta::ESHOP_ID => (string) $filter->getEshop()->getId()]];
}
if ($filter->getCategory() !== null) {
/** @var Category[] $childrenCategories */
$childrenCategories = $this->categoryRepository->find([CategoryMeta::PATH => $filter->getCategory()->getId()]);
$must[] = ["terms" => [ProductMeta::CATEGORY_IDS => array_merge([(string) $filter->getCategory()->getId()], array_map(function (Category $category) {
return (string) $category->getId();
}, $childrenCategories))]];
}
$body = ["query" => ["filtered" => ["filter" => ["bool" => ["must" => $must]]]], "from" => $filter->getOffset(), "size" => $filter->getLimit(), "sort" => ["_score" => "desc"]];
if ($filter->getQ() !== null) {
$body["query"]["filtered"]["query"] = ["multi_match" => ["query" => $filter->getQ(), "fields" => [ProductMeta::NAME . "^5", ProductMeta::LONG_NAME . "^5", ProductMeta::DESCRIPTION, ProductMeta::MANUFACTURER . "^2", ProductMeta::BRAND . "^2", ProductMeta::ESHOP . "." . EshopMeta::NAME . "^2"]]];
}
// if (empty($body["query"]["filtered"]["filter"]["bool"]["must"])) {
// unset($body["query"]["filtered"]["filter"]);
// }
$response = $this->elasticsearch->search(["index" => $this->catalogIndexAliasName, "type" => ProductMeta::SHORT_NAME, "body" => $body]);
if (!isset($response["hits"]["hits"])) {
throw new \RuntimeException("Response does not have hits->hits. Got: " . json_encode($response));
}
$products = [];
foreach ($response["hits"]["hits"] as $hit) {
$products[] = ProductMeta::fromArray($hit["_source"], "json:");
}
return $products;
}
示例13: indexAll
/**
* Index all products
*
* @return number
*/
public function indexAll()
{
$products = $this->database->table('product')->fetchAll();
foreach ($products as $product) {
$this->es->index(['index' => $this->indexName, 'type' => 'product', 'id' => $product['id'], 'body' => $product->toArray()]);
}
return count($products);
}
示例14: getParameters
/**
*
* {@inheritdoc}
*
*/
public function getParameters(View $view, FormFactoryInterface $formFactoty, Request $request)
{
$searchQuery = ['index' => $view->getContentType()->getEnvironment()->getAlias(), 'type' => $view->getContentType()->getName(), 'search_type' => 'count', 'body' => $view->getOptions()['aggsQuery']];
$retDoc = $this->client->search($searchQuery);
foreach (explode('.', $view->getOptions()['pathToBuckets']) as $attribute) {
$retDoc = $retDoc[$attribute];
}
return ['keywords' => $retDoc, 'view' => $view, 'contentType' => $view->getContentType(), 'environment' => $view->getContentType()->getEnvironment()];
}
示例15: reindex
/**
* Create the synonyms index for a store id.
*
* @param integer $storeId Store id.
* @param string[] $synonyms Raw synonyms list.
* @param string[] $expansions Raw expansions list.
*
* @return void
*/
public function reindex($storeId, $synonyms, $expansions)
{
$indexIdentifier = ThesaurusIndex::INDEX_IDENTIER;
$indexName = $this->indexSettingsHelper->createIndexNameFromIdentifier($indexIdentifier, $storeId);
$indexAlias = $this->indexSettingsHelper->getIndexAliasFromIdentifier($indexIdentifier, $storeId);
$indexSettings = ['settings' => $this->getIndexSettings($synonyms, $expansions)];
$this->client->indices()->create(['index' => $indexName, 'body' => $indexSettings]);
$this->indexManager->proceedIndexInstall($indexName, $indexAlias);
$this->cacheHelper->cleanIndexCache(ThesaurusIndex::INDEX_IDENTIER, $storeId);
}