Giter Site home page Giter Site logo

nulldrei / enterprise-search-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from elastic/enterprise-search-php

0.0 0.0 0.0 386 KB

Elastic Enterprise Search Official PHP Client

License: Apache License 2.0

PHP 95.33% Shell 4.54% Dockerfile 0.14%

enterprise-search-php's Introduction

Elastic Enterprise Search Logo

A first-party PHP client to interface with Elastic Enterpise Search including Elastic App Search and Elastic Workplace Search.

Contents


Getting started ๐Ÿฃ

Using this client assumes that you have a Enterprise Search server installed and running.

You can install the client in your project by using composer:

composer require elastic/enterprise-search

After the installation you can use the client as follows:

use Elastic\EnterpriseSearch\Client;
use Elastic\EnterpriseSearch\EnterpriseSearch\Request;

$client = new Client([
    'host' => 'http://localhost:3002',
    'enterprise-search' => [
        'username' => '<insert here the username>',
        'password' => '<insert here the password>'
    ]
]);

$es = $client->enterpriseSearch(); // Enterprise Search endpoints

$result = $es->getVersion(new Request\GetVersion); // Call the getVersion endpoint

echo $result->number; // prints the Enterprise Search version (e.g. 7.11.0)

You can access the result of each endpoints using object or array interface, as follows:

$result = $es->getVersion(new Request\GetVersion);

echo $result->number; // prints the Enterprise Search version (e.g. 7.11.0)
echo $result['number']; // same as above

var_dump($result->asArray());  // returns all the body response as array
var_dump($result->asObject()); // returns all the body response as object
var_dump($result->asString()); // returns all the body response as string (i.e. JSON)

Moreover, you can access the full HTTP response of the result using a PSR-7 object.

$result = $es->getVersion(new Request\GetVersion);

$response = $result->getResponse(); // PSR-7 object
echo $response->getStatusCode();    // e.g. 200
var_dump($response->getHeaders());  // returns all the response headers

Versioning

This client is versioned and released alongside Enterprise Search.

To guarantee compatibility, use the most recent version of this library within the major version of the corresponding Enterprise Search implementation.

For example, for Enterprise Search 7.4, use 7.4 of this library or above, but not 8.0.

Usage

The Enterprise Search PHP client provides API for the following Elastic products:

Enterprise Search API

You can consume the Enterprise Search APIs using the Client::enterpriseSearch() function.

For instance, you can enable the Read-Only mode flag endpoint as follows:

use Elastic\EnterpriseSearch\Client;
use Elastic\EnterpriseSearch\EnterpriseSearch\Request;
use Elastic\EnterpriseSearch\EnterpriseSearch\Schema;

$client = new Client([
    'host' => 'http://localhost:3002',
    'enterprise-search' => [
        'username' => '<insert here the username>',
        'password' => '<insert here the password>'
    ]
]);

$es = $client->enterpriseSearch();

$result = $es->putReadOnly(
    new Request\PutReadOnly(
        new Schema\ReadOnlyState(true)
    )
);

var_dump($result['enabled']); // true

For more information about the Enterprise Search API you can read the official documentation here.

App Search API

You can consume the App Search APIs using the Client::appSearch() function.

For instance, you can create an Engine using the following endpoint:

use Elastic\EnterpriseSearch\Client;
use Elastic\EnterpriseSearch\AppSearch\Request;

$client = new Client([
    'host' => 'http://localhost:3002',
    'app-search' => [
        'token' => '<insert here the API-KEY>'
    ]
]);

$app = $client->appSearch();

// Create a 'test' engine
$result = $appSearch->createEngine(
    new Request\CreateEngine(
        new Schema\Engine('test')
    )
);

var_dump($result->name); // test
var_dump($result->document_count); // 0, since just created

For more information about the App Search API you can read the official documentation here.

Workplace API

You can consume the Workplace Search APIs using the Client::workplaceSearch() function.

For instance, you can index a document in Workplace Search using the following endpoint:

use Elastic\EnterpriseSearch\Client;
use Elastic\EnterpriseSearch\WorkplaceSearch\Request;
use Elastic\EnterpriseSearch\WorkplaceSearch\Schema;

$client = new Client([
    'host' => 'http://localhost:3002',
    'workplace-search' => [
        'token' => '<insert here the AUTH_TOKEN>'
    ]
]);

$workplace = $client->workplaceSearch();

// create a new document (id is optional)
$doc = new Schema\Document();
$doc->id = '1234';
$doc->title = "The Meaning of Time";
$doc->body = "Not much. It is a made up thing.";

$result = $workplace->indexDocuments(
    new Request\IndexDocuments('<content source ID>', [$doc])
);

var_dump($result->results); // return the results

For more information about the Workplace Search API you can read the official documentation here.

FAQ ๐Ÿ”ฎ

Where do I report issues with the client?

If something is not working as expected, please open an issue.

Where else can I go to get help?

You can checkout the Elastic community discuss forums.

Contribute ๐Ÿš€

We welcome contributors to the project. Before you begin, a couple notes...

License ๐Ÿ“—

Apache 2.0 ยฉ Elastic

enterprise-search-php's People

Contributors

afoucret avatar chriscressman avatar ezimuel avatar philkra avatar

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.